//-------------------------------页面初始化开始-----------------------------------------------
Ext.onReady(function(){
    // 树形配置开始
    var tree = new Ext.tree.TreePanel({
	    loader: new Ext.tree.TreeLoader(),
        title: '系统管理',
        split: true,
        border: true,
		rootVisible:false,
        collapsible: true,
        width: 120,
        minSize: 80,
        maxSize: 200
    });
	
	//单击树事件开始
	tree.on("click",function(node,event){
		if(!node.isLeaf()){return;}
		event.stopEvent();
		//var user_p = "1,10,11,12,13,14,15,16,17,18";   ////////////////////////////////////////////////////临时测试
		var n = tabpanel.getComponent(node.id);
		var k  = tabpanel.find('title',node.text);
		if(n || k!=''){tabpanel.setActiveTab(node.id);return}
		//生成右侧的网点管理、图标管理等数据
		switch(node.id){
			case "customerInfo":	//客户信息开始
				if (userTypeTF(user_p,11)){
					var hall_grid_n = tabs.add(grid_customerInfo);
					tabs.setActiveTab(hall_grid_n);
					customerInfo_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(customerInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;
			case "saleAreaTree":	//销售片区管理开始
				if (userTypeTF(user_p,13)){
					var saleArea_grid_n = tabs.add(grid_saleArea);
					tabs.setActiveTab(saleArea_grid_n);
					saleArea_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(saleArea_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;	
			case "salesTree":	//销售人员管理开始
				if (userTypeTF(user_p,14)){
					var sales_grid_n = tabs.add(grid_sales);
					tabs.setActiveTab(sales_grid_n);
					sales_search.load({
						params:{
							start: 0,
							limit:20
						}
					,callback:function(r,options,success){if(sales_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;	
			case "iconInfoTree":	//标注图标管理开始
				if (userTypeTF(user_p,18)){
					var iconInfo_grid_n = tabs.add(grid_iconInfo);
					tabs.setActiveTab(iconInfo_grid_n);
					iconInfo_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(iconInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;
			case "wangdianTree":	//网点管理开始
				if (userTypeTF(user_p,10)){
					var wangdian_grid_n = tabs.add(grid_wangdian);
					tabs.setActiveTab(wangdian_grid_n);
					wangdian_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(wangdian_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;
			case "routeInfo":	//行程管理
				if (userTypeTF(user_p,12)){
					var routeInfo_grid_n = tabs.add(grid_routeInfo);
					tabs.setActiveTab(routeInfo_grid_n);
					routeInfo_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(routeInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;
			case "getPositionMsgTree":	//采集管理开始
				//if (userTypeTF(user_p,15)){
					var getPositionMsg_grid_n = tabs.add(grid_getPositionMsg);
					tabs.setActiveTab(getPositionMsg_grid_n);
					getPositionMsg_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(getPositionMsg_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				//}else{
					//alert("无此权限");
				//}
				break;	
			case "getPositionUserTree":	//人员定位管理开始
				//if (userTypeTF(user_p,15)){
					var getPositionUser_grid_n = tabs.add(grid_getPositionUser);
					tabs.setActiveTab(getPositionUser_grid_n);
					getPositionUser_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(getPositionUser_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				//}else{
					//alert("无此权限");
				//}
				break;
			case "departmentTree":	//部门管理开始
				if (userTypeTF(user_p,15)){
					var department_grid_n = tabs.add(grid_department);
					tabs.setActiveTab(department_grid_n);
					department_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(department_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;
			case "positionTree":	//职位管理开始
				if (userTypeTF(user_p,16)){
					var position_grid_n = tabs.add(grid_position);
					tabs.setActiveTab(position_grid_n);
					position_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(position_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;
			case "userTree":	//用户信息开始
				if (userTypeTF(user_p,17)){
					var user_grid_n = tabs.add(grid_user);
					tabs.setActiveTab(user_grid_n);
					user_search.load({
						params:{
							start: 0,
							limit:20
						}
						,callback:function(r,options,success){if(user_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					});
				}else{
					alert("无此权限");
				}
				break;
			case 'out':location.href="login.asp";break;//11054572,3561267
			default:break;
		}
    });
	
	//单击树事件结束
	var root = new Ext.tree.AsyncTreeNode({
		text:'',
		children: [
			{text:'客户信息管理',id:'customerInfo',leaf:true},
			{text:'销售片区管理',id:'saleAreaTree',leaf:true},
			{text:'销售人员管理',id:'salesTree',leaf:true},
			{text:'网点信息管理',id:'wangdianTree',leaf:true},
			{text:'标注图标管理',id:'iconInfoTree',leaf:true},
			{text:'行程管理',id:'routeInfo',leaf:true},
			{text:'采集管理',id:'getPositionMsgTree',leaf:true},
			{text:'人员定位管理',id:'getPositionUserTree',leaf:true},
			{text:'部门管理',id:'departmentTree',leaf:true},
			{text:'职位管理',id:'positionTree',leaf:true},
			{text:'用户管理',id:'userTree',leaf:true},
			{text:'退出系统',id:'out',leaf:true}
		]
	});
    tree.setRootNode(root);
    tree.expand();
    // 树形配置结束
    
	//查询TAB
	var tabpanel=new Ext.TabPanel({
        activeTab:0,    //设置默认选择的选项卡
        width:300,
		height:700
		//,items:[grid,form]
    });
	//查询TAB结束
	
	//管理TAB开始
	var tabs = new Ext.TabPanel({
        //renderTo: 'tab',
        height: 100,
		region:'center',
		loadMask: true,
		//closable: true,
        enableTabScroll: true
    });
    tabs.add({
        title: '说明',
		   el:'shuoming'
        //html: '内容1'
    });
    tabs.activate(0);
	//管理TAB结束
	
    // 布局开始
    var viewport = new Ext.Viewport({
        layout:'border',
        items:[{
				region: 'north',
				contentEl: 'north-div',
				height: 55,
				bodyStyle: 'background-color:#BBCCEE;'
			},{
				region: 'south',
				contentEl: 'south-div',
				height: 20,
				bodyStyle: 'background-color:#BBCCEE;'
			},{ region: 'west',
				split: true,
				layout:'accordion',
				width:300,
				collapsible:true,
				title:'系统菜单',
				items:[tree]
			},tabs
		]
    });
    // 布局结束
});
//--------------------------------页面初始化结束-----------------------------------------------


//--------------------------------客户信息管理开始--------------------------------------------------
var customerInfo_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var customerInfo_cm = new Ext.grid.ColumnModel([customerInfo_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'客户名称',dataIndex:'customerName'},
	{header:'客户办公地址',dataIndex:'customerOfficeAdress'},
	{header:'客户办公地址经度',dataIndex:'customerOfficeAdressLng'},
	{header:'客户办公地址纬度',dataIndex:'customerOfficeAdressLat'},
	{
		header:'客户仓库地址',
		dataIndex:'customerStoreHouse'
		//,
//			renderer:function(value){
//				return entTypeDes(value);
//			}
	},
	{header:'客户仓库地址纬度',dataIndex:'customerStoreHouseLng'},
	{header:'客户仓库地址纬度',dataIndex:'customerStoreHouseLat'},
	{header:'所属城市',dataIndex:'province'},
	{header:'市',dataIndex:'city',hidden:true},
	{header:'区',dataIndex:'district',hidden:true},
	{header:'客户辖区',dataIndex:'kehuxiaqu'},
	{header:'客户负责人',dataIndex:'kehufuzeren'},
	{header:'客户负责人联系方式',dataIndex:'kehufuzerenTel'},
	{header:'备注信息',dataIndex:'beizhu'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_customerInfo = new Ext.data.HttpProxy({url:'json_customerInfoSearch.asp'});
var reader_customerInfo = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'customerName'},
		{name:'customerOfficeAdress'},
		{name:'customerOfficeAdressLng'},
		{name:'customerOfficeAdressLat'},
		{name:'customerStoreHouse'},
		{name:'customerStoreHouseLng'},
		{name:'customerStoreHouseLat'},
		{name:'province'},
		{name:'city'},
		{name:'district'},
		{name:'kehuxiaqu'},
		{name:'kehufuzeren'},
		{name:'kehufuzerenTel'},
		{name:'beizhu'}
	]
);
//构建Store
customerInfo_search = new Ext.data.Store({
	proxy:proxy_customerInfo,
	reader:reader_customerInfo
/*		,
	baseParams:{limit:5}*/
});

var grid_customerInfo = new Ext.grid.GridPanel({
	store: customerInfo_search,
	cm: customerInfo_cm,
	loadMask: true,
	//closable: true,
	title: '客户信息列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:customerInfo_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'customerKeyWord',name:'customerKeyWord',allowBlank: true,emptyText: "搜索客户名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				customerInfo_search.removeAll();
				customerInfo_search.load({
					params:{
						start: 0,
						limit:20,
						customerKeyWord:grid_customerInfo.getTopToolbar().findById("customerKeyWord").getValue()
					},callback:function(r,options,success){if(customerInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{xtype: "tbseparator"},
		{
			text: 'Excel导入',
			icon: "img/chart_pie_add.png",
			cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				//hall_form_obj = getHallForm();
				customerInfo_win = new Ext.Window(
					{
						title:'Excel导入',
						id:'win',
						width:400,
						height:130,
						modal : true,
						maximizable:true,
						items:excelFileUploadkh()
					}
				);
				customerInfo_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				hall_form_obj = getCustomerInfoForm();
				customerInfo_win = new Ext.Window({title: "添加客户信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: hall_form_obj});
				customerInfo_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_customerInfo.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					hall_form_obj = getCustomerInfoForm(row[i]);
					customerInfo_win = new Ext.Window({title: "修改客户信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: hall_form_obj});
					customerInfo_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"}, 
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_customerInfo.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_customerInfoDelete.asp',
									params: 'id=' + row[i].get("id")
								});
							}
							customerInfo_search.removeAll();
							customerInfo_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		},
		{xtype: "tbseparator"}, 
		{
			text: 'Excel模版下载',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				//window.open
				window.location.href = "download/客户信息数据.xls";
			}
		}
	]
});

//生成新加机构点的菜单
function getCustomerInfoForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'hall_form',
		name: 'hall_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 640,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'customerName',fieldLabel: '客户名称',width:150,allowBlank:false,blankText: '客户名称不能为空',value:(row?row.get("customerName"):"")},	//行1
			{xtype: 'button',handler:function(){citysWin(cityOptions);}, name: 'province_city_district',id:"province_city_district",fieldLabel: '选择城市',text:'选择',width: 120,height:22},
			{ // 行2
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'province',id:'province',fieldLabel: '所在城市',width: 150,allowBlank:false,blankText: '省不能为空',value:(row?row.get("province"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 60,
						items: [{xtype: 'textfield',name:'city',id:'city',fieldLabel: '市',width: 70,value:(row?row.get("city"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 12,
						items: [{xtype: 'textfield',name:'district',id:'district',fieldLabel: '区',width: 70,value:(row?row.get("district"):"")}]
					}
				]
			},
			{ //行3
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5, // 该列有整行中所占百分比
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'customerOfficeAdress',fieldLabel: '客户办公地址',width: 150,allowBlank:false,blankText: '客户办公地址不能为空',value:(row?row.get("customerOfficeAdress"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						labelWidth: 120,
						items: [{xtype: 'button',handler:function(){showWin_Lnglat(setOfficeAddressLnglat,Ext.getCmp("customerOfficeAdressLng").getValue(),Ext.getCmp("customerOfficeAdressLat").getValue());}, name: 'latlng_OfficeAdress',id:"hall_ezmarker_OfficeAdress",fieldLabel: '客户办公位置',text:'地图标注',width: 120,height:22}]
					}
				]
			},
			{ // 行4
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'customerOfficeAdressLng',id:'customerOfficeAdressLng',fieldLabel: '客户办公地址经度',width: 150,allowBlank:false,blankText: '经度不能为空',value:(row?row.get("customerOfficeAdressLng"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'customerOfficeAdressLat',id:'customerOfficeAdressLat',fieldLabel: '客户办公地址纬度',width: 150,allowBlank:false,blankText: '纬度不能为空',value:(row?row.get("customerOfficeAdressLat"):"")}]
					}
				]
			},
			
			{ // 行5
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'customerStoreHouse',fieldLabel: '客户仓库地址',width: 150,allowBlank:false,blankText: '客户仓库地址不能为空',value:(row?row.get("customerStoreHouse"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'button',handler:function(){showWin_Lnglat(setStoreHouseLnglat,Ext.getCmp("customerStoreHouseLng").getValue(),Ext.getCmp("customerStoreHouseLat").getValue());}, name: 'latlng_StoreHouse',id:"hall_ezmarker_StoreHouse",fieldLabel: '客户仓库位置',text:'地图标注',width: 120,height:22}]
					}
				]
			},
			{ // 行6
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'customerStoreHouseLng',id:'customerStoreHouseLng',fieldLabel: '客户仓库地址经度',width: 150,allowBlank:false,blankText: '经度不能为空',value:(row?row.get("customerStoreHouseLng"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'customerStoreHouseLat',id:'customerStoreHouseLat',fieldLabel: '客户仓库地址纬度',width: 150,allowBlank:false,blankText: '纬度不能为空',value:(row?row.get("customerStoreHouseLat"):"")}]
					}
				]
			},
			{ // 行7
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'kehuxiaqu',id:'kehuxiaqu',fieldLabel: '客户辖区',width: 150,allowBlank:false,blankText: '客户辖区不能为空',value:(row?row.get("kehuxiaqu"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'button',handler:function(){citysWin(cityXiaQuOptions);}, name: 'province_city_kehuxiaqu',id:"province_city_kehuxiaqu",text:'选择客户辖区',width: 120,height:20}]
					}
				]
			},
			//{xtype: 'textfield',name:'kehuxiaqu',id:'kehuxiaqu',fieldLabel: '客户辖区',width: 150,allowBlank:false,blankText: '客户辖区不能为空',value:(row?row.get("kehuxiaqu"):"")},
			{xtype: 'textfield',name:'kehufuzeren',id:'kehufuzeren',fieldLabel: '客户负责人',width: 150,allowBlank:false,blankText: '客户负责人不能为空',value:(row?row.get("kehufuzeren"):"")},
			{xtype: 'textfield',name:'kehufuzerenTel',id:'kehufuzerenTel',fieldLabel: '客户负责人联系方式',width: 150,allowBlank:false,blankText: '客户负责人联系方式不能为空',value:(row?row.get("kehufuzerenTel"):"")},
			{xtype: 'textarea',fieldLabel: '备注信息',id: 'beizhu',anchor: '70%',name:'beizhu',height: 90,value:(row?row.get("beizhu"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (customerInfo_win.getComponent('hall_form').form.isValid()) {
					customerInfo_win.getComponent('hall_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_customerInfo.asp',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加客户信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改客户信息成功!');
								}
								customerInfo_win.getComponent('hall_form').form.reset();
								customerInfo_search.load({params: {start: 0,limit:20}});
								customerInfo_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加客户信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改客户信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							customerInfo_search.load({params: {start: 0}});
							customerInfo_win.getComponent('hall_form').form.reset();
							//customerInfo_win.getComponent('hall_form').findById("hall_ezmarker").reset();
						}
						
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				customerInfo_win.close();
			}
		}]
	});
}

//客户信息管理城市列表窗口
/*function customerCitysWin()
{
	citys_form_obj = citysForm(cityOptions);
	customerCitys_win = new Ext.Window({title: "城市列表",width: 213,height:375,modal: true,maximizable: false,resizable:false,items: citys_form_obj});
	customerCitys_win.show();
}*/
//给客户的所属城市赋值
function cityOptions(cityArr)
{
	Ext.getDom("province").value = cityArr.reverse().join("");
}

function cityXiaQuOptions(cityArr)
{
	Ext.getDom("kehuxiaqu").value = cityArr.reverse().join("");
}

//地图标注方法
var ezmarkerEvent = null;
function showWin_Lnglat(fun,lng,lat)
{
	//ezmarker.win.config.canClose = 1;
	//ezmarker.createWin(ezmarker.win.config);
	ezmarker.setWinZIndex(100000);
	//ezmarker.win.setContainerSize([650,450]);	//设置标注层的大小
	var ezmarkerDiv = document.getElementById("ezmarkerDiv");
	ezmarkerDiv.style.cssText = "position:absolute;width:650px;height:450px;left:50%;top:50%;margin-left:-325px;margin-top:-225px;z-index:100000;display:block";
	
	var ezmarkerDivClose = document.getElementById("ezmarkerDivClose");
	ezmarkerDivClose.style.cssText = "position:absolute;width:14px;height:14px;left:50%;top:50%;margin-left:300px;margin-top:-220px;z-index:100000;display:block;background:url(http://api.51ditu.com/img/ezmarker/close.gif);cursor:pointer";
	ezmarkerDivClose.onclick = function(){
		LTEvent.removeListener(ezmarkerEvent);
		document.getElementById("ezmarkerDiv").style.display = "none";
		document.getElementById("ezmarkerDivClose").style.display = "none";
	};
	
	if(lng!=""&&lat!="")
	{
		ezmarker.map.clearOverLays();
		ezmarker.setValue(new LTPoint(lng,lat),6);//设置默认值
	}
	else
	{
		ezmarker.map.clearOverLays();
	}
	
	ezmarkerEvent = LTEvent.addListener(ezmarker,"mark",fun);	//在每次用户完成标注的时候执行check函数
}
//设置项目办公地址经纬度
function setOfficeAddressLnglat(point,zoom)
{
	LTEvent.removeListener(ezmarkerEvent);
	Ext.getDom("customerOfficeAdressLng").value = point.getLongitude();
	Ext.getDom("customerOfficeAdressLat").value = point.getLatitude();
	document.getElementById("ezmarkerDiv").style.display = "none";
	document.getElementById("ezmarkerDivClose").style.display = "none";
}
//设置客户仓库地址经度
function setStoreHouseLnglat(point,zoom)
{
	LTEvent.removeListener(ezmarkerEvent);
	Ext.getDom("customerStoreHouseLng").value = point.getLongitude();
	Ext.getDom("customerStoreHouseLat").value = point.getLatitude();
	document.getElementById("ezmarkerDiv").style.display = "none";
	document.getElementById("ezmarkerDivClose").style.display = "none";
}
//excel
function excelFileUploadkh(){
	var excel = new Ext.FormPanel({
		region : 'center', 
		labelWidth : 35, 
		frame : true,
		bodyStyle : 'padding:5px 5px 0', 
		autoScroll : true, 
		border : false, 
		fileUpload : true, 
		items : [
			{
				xtype : 'textfield',
				fieldLabel : '文件', 
				name : 'file', 
				id:'file', 
				inputType : 'file',
				width : 260,
				allowBlank : true,
				blankText : '文件不能为空', 
				height : 25,
				anchor : '90%'
			},
			{
				bodyStyle:"padding-left:60px",
				html:"<br/><span><font color='#666666'></font></span>" 
			}
		],
		buttons : [
			{
				text : '确定',
				type : 'submit',
				handler : function() {
					if(document.getElementById("file").value == '') return; 
					if (!excel.form.isValid()) {return;}
					excel.form.submit(
						{
							waitTitle: '请稍候',
							waitMsg : '正在上传 ......', 
							url : 'Save_khInfo.asp', 
							success : function(form, action) {
								customerInfo_win.close();
								//alert("开始");
								//alert(obj2str(action.result));
								Ext.MessageBox.alert('提示', action.result.message);
								
								customerInfo_search.load({params:{start:0,limit:20}});
								//alert("上传成功");
							},
							failure : function(form, action) { 
								customerInfo_win.close();
								Ext.MessageBox.alert('提示', action.result.message);
								//alert("上传失败");
							}
						}
					);
				}
			},
			{
				text : '关闭',
				type : 'submit',
				handler : function() {
					customerInfo_win.close();
				}
			}
		]
	});
	return excel;
}

//--------------------------------客户信息管理结束-------------------------------------------------	


//--------------------------------销售片区管理开始-------------------------------------------------	
var saleArea_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var saleArea_cm = new Ext.grid.ColumnModel([saleArea_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'销售片区名称',dataIndex:'saleAreaName'},
	{header:'销售片区范围',dataIndex:'salerId'},
	{header:'销售片区面积',dataIndex:'saleArea'},
	{header:'销售片区颜色',dataIndex:'areaColor',renderer : function(v,m){
			return "<div style='background:#"+v+"'>"+v+"</div>";
		}
	},
	{header:'类别',dataIndex:'areaGrade',
		renderer:function(value){
			return "一级片区";
		}
	},
	{header:'上一级片区',dataIndex:'owenArea',hidden:true},
	{header:'下属片区',dataIndex:'addSecondSaleArea',width:130,renderer:addSecondSaleArea}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_saleArea = new Ext.data.HttpProxy({url:'json_saleAreaSearch.asp?saleType=1'});
var reader_saleArea = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'saleAreaName'},
		{name:'salerId'},
		{name:'saleArea'},
		{name:'areaColor'},
		{name:'areaGrade'},
		{name:'owenArea'}
	]
);
//构建Store
saleArea_search = new Ext.data.Store({
	proxy:proxy_saleArea,
	reader:reader_saleArea
});

var grid_saleArea = new Ext.grid.GridPanel({
	store: saleArea_search,
	cm: saleArea_cm,
	loadMask: true,
	//closable: true,
	title: '销售片区列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:saleArea_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'saleAreaNameKeyWord',name:'saleAreaNameKeyWord',allowBlank: true,emptyText: "搜索销售片区名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				saleArea_search.removeAll();
				saleArea_search.load({
					params:{
						start: 0,
						limit:20,
						saleAreaNameKeyWord:grid_saleArea.getTopToolbar().findById("saleAreaNameKeyWord").getValue()
					},callback:function(r,options,success){if(saleArea_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				saleArea_form_obj = getSaleAreaForm();
				saleArea_win = new Ext.Window({title: "添加销售片区",width: 360,height: 210,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
				saleArea_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_saleArea.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					saleArea_form_obj = getSaleAreaForm(row[i]);
					saleArea_win = new Ext.Window({title: "修改销售片区",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
					saleArea_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_saleArea.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_saleAreaDelete.asp?saleType=1',
									params: 'id=' + row[i].get("id")
								});
							}
							saleArea_search.removeAll();
							saleArea_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});



//生成新加机构点的菜单
function getSaleAreaForm(row)
{
	
	var cf = new Ext.form.ColorField({
		fieldLabel: '销售片区颜色',
		id: 'areaColor',
		name: 'areaColor',
		width : 150,
		showHexValue:true,
		allowBlank:false,
		blankText: '销售片区颜色不能为空',
		defaultColor:(row?row.get("areaColor"):"ffffff")
	});
	
	//网点数据结束
	return new Ext.FormPanel({
		id: 'saleArea_form',
		name: 'saleArea_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'saleAreaName',fieldLabel: '销售片区名称',width:150,allowBlank:false,blankText: '销售片区名称不能为空',value:(row?row.get("saleAreaName"):"")},
			{xtype: 'button',handler:function(){citysWin(saleAreaCityOptions,2);}, name: 'saleArea_ID',id:"saleArea_ID",fieldLabel: '销售片区',text:'请选择销售片区',width: 120,height:22},
			{xtype: 'textfield',name:'salerId',id:'salerId',fieldLabel: '销售片区范围',width: 150,allowBlank:false,blankText: '销售片区不能为空',value:(row?row.get("salerId"):"")},
			{xtype: 'textfield',name:'saleArea',id:'saleArea',fieldLabel: '销售片区面积',width: 150,allowBlank:false,blankText: '销售片区面积不能为空',value:(row?row.get("saleArea"):"")},
			//{xtype: 'textfield',name:'areaColor',id:'areaColor',fieldLabel: '销售片区颜色',width: 150,allowBlank:false,blankText: '销售片区颜色不能为空',value:(row?row.get("areaColor"):"")},
			cf,
			{hidden:true,xtype: 'hidden',name:'areaGrade',id:'areaGrade',fieldLabel: '类别',width: 150,value:(row?row.get("areaGrade"):1)},
			{hidden:true,xtype: 'hidden',name:'owenArea',id:'owenArea',fieldLabel: '上一级片区',width: 150,value:(row?row.get("owenArea"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (saleArea_win.getComponent('saleArea_form').form.isValid()) {
					saleArea_win.getComponent('saleArea_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_saleArea.asp',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加销售片区成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改销售片区成功!');
								}
								saleArea_win.getComponent('saleArea_form').form.reset();
								saleArea_search.load({params: {start: 0,limit:20}});
								saleArea_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加销售片区失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改销售片区失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							saleArea_search.load({params: {start: 0}});
							saleArea_win.getComponent('saleArea_form').form.reset();
							//customerInfo_win.getComponent('saleArea_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				saleArea_win.close();
			}
		}]
	});
}

//给客户的所属城市赋值
function saleAreaCityOptions(cityArr)
{
	Ext.getDom("salerId").value = cityArr.join(",");
}
//--------------------------------销售片区管理结束-------------------------------------------------
//--------------------------------销售片区二级片区管理开始---------------------------------------------
//添加二级片区
function addSecondSaleArea(value,cellmeta,record,rowIndex,columnIndex,store)
{
	var str="<input type='button' value='添加二级片区' onclick='secondSaleAreaWin(\""+record.data["id"]+"\",\""+record.data["saleAreaName"]+"\")'\>"
	//alert(str);
	return str;
}

function secondSaleAreaWin(id,saleAreaName)
{
	secondSaleArea_form_obj = secondSaleAreaForm(id,saleAreaName);
	secondSaleArea_win = new Ext.Window({title: "二级片区列表",width: 664,height:500,modal: true,maximizable: false,resizable:false,items: secondSaleArea_form_obj});
	secondSaleArea_win.show();
}
function secondSaleAreaForm(id,saleAreaName)
{
	var form1 = new Ext.form.FormPanel({
		width:650,
		height:480,
		region:'center',
		loadMask: true,
		//closable: true,
        enableTabScroll: true,
		//frame:true,//圆角和浅蓝色背景
		//renderTo:Ext.getBody(),//呈现
		//title:"FormPanel",
		//bodyStyle:"padding:5px 5px 0",
		//defaults:{xtype:"textfield",width:120},
		items:[
			secondSaleAreaFormPanel(id,saleAreaName)
		]
	});
	return form1;
}
function secondSaleAreaFormPanel(id,saleAreaName)
{
	var saleArea_sm_second = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
	var saleArea_cm_second = new Ext.grid.ColumnModel([saleArea_sm_second,
		{header:'编号',dataIndex:'id',hidden:true},
		{header:'销售片区名称',dataIndex:'saleAreaName'},
		{header:'销售片区范围',dataIndex:'salerId'},
		{header:'销售片区面积',dataIndex:'saleArea'},
		{header:'销售片区颜色',dataIndex:'areaColor',renderer : function(v,m){
			return "<div style='background:#"+v+"'>"+v+"</div>";
		}},
		{header:'类别',dataIndex:'areaGrade',
			renderer:function(value){
				return "二级片区";
			}
		},
		{header:'上一级片区',dataIndex:'owenArea'}
	]);
	//start 读取远程POI JSON数据显示在表格里
	var proxy_saleArea_second = new Ext.data.HttpProxy({url:'json_saleAreaSearch.asp?saleType=2'});
	var reader_saleArea_second = new Ext.data.JsonReader(
		{
			totalProperty:'mytotal',//记录总数
			root:'root',
			id:'id'
		},[
			{name:'id'},
			{name:'saleAreaName'},
			{name:'salerId'},
			{name:'saleArea'},
			{name:'areaColor'},
			{name:'areaGrade'},
			{name:'owenArea'},
			{name:'saleAreaLv1'}
		]
	);
	//构建Store
	saleArea_search_second = new Ext.data.Store({
		proxy:proxy_saleArea_second,
		reader:reader_saleArea_second
	});
	
	var grid_saleArea_second = new Ext.grid.GridPanel({
		store: saleArea_search_second,
		cm: saleArea_cm_second,
		loadMask: true,
		width:650,
		height:468,
		//closable: true,
		//title: '销售片区列表',
		bbar: new Ext.PagingToolbar({
			pageSize:20,
			store:saleArea_search_second,
			displayInfo:true,
			//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
			displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
			emptyMsg:'没有记录',
			beforePageText: "第",
			afterPageText:"页 共{0}页"
		}),
		tbar: [
			{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'saleAreaNameKeyWord_second',name:'saleAreaNameKeyWord_second',allowBlank: true,emptyText: "搜索销售片区名称"},
			{xtype: "tbseparator"},
			{
				text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
				handler: function(){
					//Ext.Msg.alert('提示','目前无数据');
					saleArea_search_second.removeAll();
					saleArea_search_second.load({
						params:{
							start: 0,
							limit:20,
							owenAreaId:id,
							saleAreaNameKeyWord:grid_saleArea_second.getTopToolbar().findById("saleAreaNameKeyWord_second").getValue()
						},callback:function(r,options,success){if(saleArea_search_second.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
					})
				}
			},
			{
				text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
				handler: function(){
					Ext.QuickTips.init();//开启表单提示
					saleArea_form_obj = getSaleAreaSecondForm(id,saleAreaName);
					secondSaleArea_win = new Ext.Window({title: "添加销售片区",width: 360,height: 210,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
					secondSaleArea_win.show();
				}
			},
			{xtype: "tbseparator"},
			{
				text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
				handler: function(){
					Ext.QuickTips.init();//开启表单提示
					var row = grid_saleArea_second.getSelectionModel().getSelections();
					if (!row){return;}
					for (var i = 0; i < row.length; i++)
					{
						Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
						saleArea_form_obj = getSaleAreaSecondForm(id,saleAreaName,row[i]);
						secondSaleArea_win = new Ext.Window({title: "修改销售片区",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: saleArea_form_obj});
						secondSaleArea_win.show();
						//field = hall_form_obj.getForm().findField('icon');
						//field.setValue(row[i].get("icon"));//new
						//alert(row[i].get("icon"))
					}
				}
			},
			{xtype: "tbseparator"},
			{
				text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
				handler: function(){
					var row = grid_saleArea_second.getSelectionModel().getSelections();
					if (row) {
						Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
							if (butten == "yes") {
								for (var i = 0; i < row.length; i++) {
									//alert(row[i].get("id"));
									Ext.Ajax.request({
										url: 'json_saleAreaDelete.asp?saleType=2',
										params: 'id=' + row[i].get("id")
									});
								}
								saleArea_search_second.removeAll();
								saleArea_search_second.load({params: {start:0,limit:20,owenAreaId:id}});
							}
						})
					}
				}
			}
		]
	});
	saleArea_search_second.load({params: {start:0,limit:20,owenAreaId:id}});
	return grid_saleArea_second;
}

//生成新加机构点的菜单
function getSaleAreaSecondForm(owenAreaId,saleAreaNameParam,row)
{
	
	var cf = new Ext.form.ColorField({
		fieldLabel: '销售片区颜色',
		id: 'areaColorSecond',
		name: 'areaColorSecond',
		width : 150,
		showHexValue:true,
		allowBlank:false,
		blankText: '销售片区颜色不能为空',
		defaultColor:(row?row.get("areaColor"):"ffffff")
	});
	
	//网点数据结束
	return new Ext.FormPanel({
		id: 'saleArea_Second_form',
		name: 'saleArea_Second_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'owenAreaId',value:owenAreaId},
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'saleAreaNameSecond',fieldLabel: '销售片区名称',width:150,allowBlank:false,blankText: '销售片区名称不能为空',value:(row?row.get("saleAreaName"):"")},
			{xtype: 'button',handler:function(){citysWin(saleAreaSecondCityOptions,2);}, name: 'saleAreaSecond_ID',id:"saleAreaSecond_ID",fieldLabel: '销售片区',text:'请选择销售片区',width: 120,height:22},
			{xtype: 'textfield',name:'salerIdSecond',id:'salerIdSecond',fieldLabel: '销售片区范围',width: 150,allowBlank:false,blankText: '销售片区不能为空',value:(row?row.get("salerId"):"")},
			{xtype: 'textfield',name:'saleAreaSecond',id:'saleAreaSecond',fieldLabel: '销售片区面积',width: 150,allowBlank:false,blankText: '销售片区面积不能为空',value:(row?row.get("saleArea"):"")},
			//{xtype: 'textfield',name:'areaColorSecond',id:'areaColorSecond',fieldLabel: '销售片区颜色',width: 150,allowBlank:false,blankText: '销售片区颜色不能为空',value:(row?row.get("areaColor"):"")},
			cf,
			{hidden:true,xtype: 'hidden',name:'areaGradeSecond',id:'areaGradeSecond',fieldLabel: '类别',width: 150,value:(row?row.get("areaGrade"):1)},
			{hidden:true,xtype: 'hidden',name:'owenAreaSecond',id:'owenAreaSecond',fieldLabel: '上一级片区',width: 150,value:saleAreaNameParam}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (secondSaleArea_win.getComponent('saleArea_Second_form').form.isValid()) {
					secondSaleArea_win.getComponent('saleArea_Second_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_saleAreaSecond.asp',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加销售片区成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改销售片区成功!');
								}
								secondSaleArea_win.getComponent('saleArea_Second_form').form.reset();
								saleArea_search_second.load({params: {start: 0,limit:20,owenAreaId:owenAreaId}});
								secondSaleArea_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加销售片区失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改销售片区失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							saleArea_search_second.load({params: {start:0,limit:20,owenAreaId:owenAreaId}});
							secondSaleArea_win.getComponent('saleArea_Second_form').form.reset();
							//customerInfo_win.getComponent('saleArea_Second_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				secondSaleArea_win.close();
			}
		}]
	});
}

//给客户的所属城市赋值
function saleAreaSecondCityOptions(cityArr)
{
	Ext.getDom("salerIdSecond").value = cityArr.join(",");
}
//--------------------------------销售片区二级片区管理结束---------------------------------------------



//--------------------------------销售人员管理开始-------------------------------------------------	
var sales_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var sales_cm = new Ext.grid.ColumnModel([sales_sm,
	{header:'编号',dataIndex:'id',hidden:true},
    {header:'销售人名称',dataIndex:'salesName'},
    {header:'销售人职务',dataIndex:'positionID'},
    {header:'销售人部门',dataIndex:'departmentID'},
    {header:'上级负责人',dataIndex:'superiorID'},
    {header:'联系电话',dataIndex:'salesPhone'},
    {header:'常住地址',dataIndex:'salesAddress'},
	{header:'所属片区',dataIndex:'owenArea'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_sales = new Ext.data.HttpProxy({url:'json_salesInfoSearch.asp'});
var reader_sales = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'salesName'},
		{name:'positionID'},
		{name:'departmentID'},
		{name:'superiorID'},
		{name:'salesPhone'},
		{name:'salesAddress'},
		{name:'owenArea'}
	]
);
//构建Store
sales_search = new Ext.data.Store({
	proxy:proxy_sales,
	reader:reader_sales
});

var owenareaArr=new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : []
});
var positionIDArr=new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : []
});
var departmentIDArr=new Ext.data.SimpleStore({
	fields: ['value', 'text'],
	data : []
});
var grid_sales = new Ext.grid.GridPanel({
	store: sales_search,
	cm: sales_cm,
	loadMask: true,
	//closable: true,
	title: '部门管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:sales_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'salesKeyWord',name:'salesKeyWord',allowBlank: true,emptyText: "搜销售人名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				sales_search.removeAll();
				sales_search.load({
					params:{
						start: 0,
						limit:20,
						salesKeyWord:grid_sales.getTopToolbar().findById("salesKeyWord").getValue()
					},callback:function(r,options,success){if(sales_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				sales_form_obj = getSalesForm();
				sales_win = new Ext.Window({title: "添加销售人信息",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: sales_form_obj});
				sales_win.show();
				//销售人职务选择
				Ext.Ajax.request({
					url:'json_comboData.asp?sType=position',
					method:'post',
					params:{},
					success:function(req){
						//alert(req.responseText);
						var reqSplit = req.responseText.split("|");
						var reqArry_ = [];
						for(var i=0;i<reqSplit.length;i++)
						{
							var reqArry = new Array();
							var reqSplit_douhao = reqSplit[i].split(",");
							reqArry.push(reqSplit_douhao[0]);
							reqArry.push(reqSplit_douhao[1]);
							//alert(reqArry);
							reqArry_.push(reqArry);
						}
						positionIDArr = reqArry_;
						Ext.getCmp('positionID').clearValue();
						Ext.getCmp('positionID').store.loadData(reqArry_);
					}
				});
				//销售人部门选择
				Ext.Ajax.request({
					url:'json_comboData.asp?sType=department',
					method:'post',
					params:{},
					success:function(req){
						//alert(req.responseText);
						var reqSplit = req.responseText.split("|");
						var reqArry_ = [];
						for(var i=0;i<reqSplit.length;i++)
						{
							var reqArry = new Array();
							var reqSplit_douhao = reqSplit[i].split(",");
							reqArry.push(reqSplit_douhao[0]);
							reqArry.push(reqSplit_douhao[1]);
							//alert(reqArry);
							reqArry_.push(reqArry);
						}
						departmentIDArr = reqArry_;
						Ext.getCmp('departmentID').clearValue();
						Ext.getCmp('departmentID').store.loadData(reqArry_);
					}
				});
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_sales.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					sales_form_obj = getSalesForm(row[i]);
					sales_win = new Ext.Window({title: "修改销售人信息",width: 360,height: 270,modal: true,maximizable:false,resizable:false,items: sales_form_obj});
					sales_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_sales.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_salesInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							sales_search.removeAll();
							sales_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getSalesForm(row)
{
	var comboxWithTree = new Ext.form.ComboBox({
		hiddenName:"owenArea",
		store:new Ext.data.SimpleStore({fields:[],data:[[]]}),
		fieldLabel: '销售片区',
		emptyText:"请选择片区",
		//editable:false,
		//expanded:true,
		//shadow:false,
		mode: 'local',
		triggerAction:'all',
		//height:350,
		tpl: '<tpl for="."><div style="height:200px"><div id="treeSaleArea"></div></div></tpl>',
		selectedClass:'',
		onSelect:Ext.emptyFn,
		onViewClick : Ext.emptyFn,
        assertValue : Ext.emptyFn,
		allowBlank:false,
		blankText: '销售片区不能为空',
		value:(row?row.get("owenArea"):"")
	});
	var treeSaleArea = new Ext.tree.TreePanel({
		containerScroll: true,//是否支持滚动条
		split: true,
		rootVisible:false,
		autoScroll: true,
		border:false,
		//height:350,
		loader: new Ext.tree.TreeLoader({dataUrl:'json_saleAreaTree.asp'}),
		root:new Ext.tree.AsyncTreeNode({id:'0',text:'treeRoot',expanded:true})
	});
	treeSaleArea.on('click',function(node,e){
		comboxWithTree.setValue(node.text);
		comboxWithTree.collapse();
	});
	comboxWithTree.on('expand',function(){
		treeSaleArea.render('treeSaleArea');
		treeSaleArea.root.reload();
	});
	//网点数据结束
	return new Ext.FormPanel({
		id: 'sales_form',
		name: 'sales_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'salesName',fieldLabel: '销售人名称',width:150,allowBlank:false,blankText: '销售人名称不能为空',value:(row?row.get("salesName"):"")},
			
			{
	            xtype: 'combo',
	            fieldLabel: '销售人职务',
				emptyText:"请销售人职务",
				forceSelection : true,
	            name: 'positionID',
				id:"positionID",
				value:(row?row.get("positionID"):""),
	            store: positionIDArr,
				mode:'local',
	            triggerAction: 'all',
				width:120,
	            valueField: 'value',
	            displayField: 'text',
				allowBlank:false,
				blankText: '销售人职务不能为空'
	        },//类别选择

			{
	            xtype: 'combo',
	            fieldLabel: '销售人部门',
				emptyText:"销售人部门",
				forceSelection : true,
	            name: 'departmentID',
				id:"departmentID",
				value:(row?row.get("departmentID"):""),
	            store: departmentIDArr,
				mode:'local',
	            triggerAction: 'all',
				width:120,
	            valueField: 'value',
	            displayField: 'text',
				allowBlank:false,
				blankText: '销售人部门不能为空'
	        },//类别选择
	        
			{xtype: 'textfield',name:'superiorID',fieldLabel: '上级负责人',width:150,allowBlank:false,blankText: '上级负责人不能为空',value:(row?row.get("superiorID"):"")},
			{xtype: 'textfield',name:'salesPhone',fieldLabel: '联系电话',width:150,allowBlank:false,blankText: '',value:(row?row.get("salesPhone"):"")},
			{xtype: 'textfield',name:'salesAddress',fieldLabel: '常住地址',width:150,allowBlank:false,blankText: '',value:(row?row.get("salesAddress"):"")},
			comboxWithTree
			//{
//	            xtype: 'combo',
//	            fieldLabel: '选择片区',
//				emptyText:"请选择片区",
//				forceSelection : true,
//	            name: 'owenArea',
//				id:"owenArea",
//				//value:'',
//	            store: owenareaArr,
//				mode:'local',
//	            triggerAction: 'all',
//				width:120,
//	            valueField: 'value',
//	            displayField: 'text'
//				//,
////				listeners:{
////					scope:this,
////					select:function(combo){
////					//debugger;
////						var fangshi=combo.getValue();
////						//Ext.getCmp('citycode').store.removeAll();
////						//alert(combo.getRawValue());
////						Ext.Ajax.request({
////							url:'json_comboData.asp?sType=area',
////							method:'post',
////							params:{
////								type:2,
////								shangJiName:combo.getRawValue()
////							},
////							success:function(req){
////								//alert(req.responseText);
////								var reqSplit = req.responseText.split("|");
////								var reqArry_ = [];
////								for(var i=0;i<reqSplit.length;i++)
////								{
////									var reqArry = new Array();
////									var reqSplit_douhao = reqSplit[i].split(",");
////									reqArry.push(reqSplit_douhao[0]);
////									reqArry.push(reqSplit_douhao[1]);
////									//alert(reqArry);
////									reqArry_.push(reqArry);
////								}
////								//Ext.getCmp('citycode2').clearValue();
////								//paramsType=2;
////								//Ext.getCmp('citycode2').store.loadData(reqArry_);
////								//Ext.getCmp('citycode').store.reload();
////							}
////						});
////					}
////				}
//	        }
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (sales_win.getComponent('sales_form').form.isValid()) {
					sales_win.getComponent('sales_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_salesInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加部门信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改部门信息成功!');
								}
								sales_win.getComponent('sales_form').form.reset();
								sales_search.load({params: {start: 0,limit:20}});
								sales_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加部门信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改部门信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							sales_search.load({params: {start: 0}});
							sales_win.getComponent('sales_form').form.reset();
							//customerInfo_win.getComponent('sales_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				sales_win.close();
			}
		}]
	});
}

//--------------------------------销售人员管理结束-------------------------------------------------	



//--------------------------------网点信息管理开始-------------------------------------------------	

var wangdian_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var wangdian_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var wangdian_cm = new Ext.grid.ColumnModel([wangdian_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'网点名称',dataIndex:'wangdianName'},
	{header:'网点地址',dataIndex:'wangdianAddress'},
	{header:'网点地址地图标注经度',dataIndex:'wangdianAddressLng'},
	{header:'网点地址地图标注纬度',dataIndex:'wangdianAddressLat'},
	{header:'所属城市',dataIndex:'province'},
	{header:'市',dataIndex:'city',hidden:true},
	{header:'区',dataIndex:'district',hidden:true},
	{header:'网点所属片区',dataIndex:'wangdianAreaOwen'},
	{header:'网点负责人',dataIndex:'wangdianfuzeren'},
	{header:'网点负责人联系方式',dataIndex:'wdfzrTel'},
	{header:'网点业务人员',dataIndex:'wangdianyewuren'},
	{header:'网点业务人联系方式',dataIndex:'wdywrTel'},
	{header:'网点所属客户',dataIndex:'wangdianOwen'},
	{header:'网点图片路径',dataIndex:'wangdianPhoto'},
	{header:'图标预览',align:'center',dataIndex:'imgPreview1',renderer:imgPreview1},
	{header:'备注信息',dataIndex:'beizhu'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_wangdian = new Ext.data.HttpProxy({url:'json_wangdianInfoSearch.asp'});
var reader_wangdian = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'wangdianName'},
		{name:'wangdianAddress'},
		{name:'wangdianAddressLng'},
		{name:'wangdianAddressLat'},
		{name:'province'},
		{name:'city'},
		{name:'district'},
		{name:'wangdianAreaOwen'},
		{name:'wangdianfuzeren'},
		{name:'wdfzrTel'},
		{name:'wangdianyewuren'},
		{name:'wdywrTel'},
		{name:'wangdianOwen'},
		{name:'wangdianPhoto'},
		{name:'imgPreview1'},
		{name:'beizhu'}
	]
);
//构建Store
wangdian_search = new Ext.data.Store({
	proxy:proxy_wangdian,
	reader:reader_wangdian
});

var grid_wangdian = new Ext.grid.GridPanel({
	store: wangdian_search,
	cm: wangdian_cm,
	loadMask: true,
	//closable: true,
	title: '网点信息列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:wangdian_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'wangdianNameKeyWord',name:'wangdianNameKeyWord',allowBlank: true,emptyText: "搜索网点名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				wangdian_search.removeAll();
				wangdian_search.load({
					params:{
						start: 0,
						limit:20,
						wangdianNameKeyWord:grid_wangdian.getTopToolbar().findById("wangdianNameKeyWord").getValue()
					},callback:function(r,options,success){if(wangdian_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{xtype: "tbseparator"},
		{
			text: 'Excel导入',
			icon: "img/chart_pie_add.png",
			cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				//hall_form_obj = getHallForm();
				wangdian_win = new Ext.Window(
					{
						title:'Excel导入',
						id:'win',
						width:400,
						height:130,
						modal : true,
						maximizable:true,
						items:excelFileUploadwd()
					}
				);
				wangdian_win.show();
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				wangdian_form_obj = getwangdianForm();
				wangdian_win = new Ext.Window({title: "添加网点信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: wangdian_form_obj});
				wangdian_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_wangdian.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					wangdian_form_obj = getwangdianForm(row[i]);
					wangdian_win = new Ext.Window({title: "修改网点信息",width: 650,height: 440,modal: true,maximizable:false,resizable:false,items: wangdian_form_obj});
					wangdian_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_wangdian.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_wangdianInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							wangdian_search.removeAll();
							wangdian_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		},
		{xtype: "tbseparator"}, 
		{
			text: 'Excel模版下载',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				//window.open
				window.location.href = "download/网点信息数据.xls";
			}
		}
	]
});

//生成新加机构点的菜单
function getwangdianForm(row)
{
	var comboxWithTreeWangDian = new Ext.form.ComboBox({
		hiddenName:"wangdianAreaOwen",
		store:new Ext.data.SimpleStore({fields:[],data:[[]]}),
		fieldLabel: '选择所属片区',
		emptyText:"请选择片区",
		//editable:false,
		//expanded:true,
		//shadow:false,
		mode: 'local',
		triggerAction:'all',
		//height:350,
		tpl: '<tpl for="."><div style="height:200px"><div id="treeWangDianSaleArea"></div></div></tpl>',
		selectedClass:'',
		onSelect:Ext.emptyFn,
		onViewClick : Ext.emptyFn,
        assertValue : Ext.emptyFn,
		allowBlank:false,
		blankText: '所属片区不能为空',
		value:(row?row.get("wangdianAreaOwen"):"")
	});
	var treeWangDianSaleArea = new Ext.tree.TreePanel({
		containerScroll: true,//是否支持滚动条
		split: true,
		rootVisible:false,
		autoScroll: true,
		border:false,
		//height:350,
		loader: new Ext.tree.TreeLoader({dataUrl:'json_saleAreaTree.asp'}),
		root:new Ext.tree.AsyncTreeNode({id:'0',text:'root',expanded:true})
	});
	treeWangDianSaleArea.on('click',function(node,e){
		comboxWithTreeWangDian.setValue(node.text);
		comboxWithTreeWangDian.collapse();
	});
	comboxWithTreeWangDian.on('expand',function(){
		treeWangDianSaleArea.render('treeWangDianSaleArea');
		treeWangDianSaleArea.root.reload();
	});
	
	
	//网点数据结束
	return new Ext.FormPanel({
		id: 'wangdian_form',
		name: 'wangdian_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 640,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		fileUpload : true,
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'wangdianName',fieldLabel: '网点名称',width:150,allowBlank:false,blankText: '网点名称不能为空',value:(row?row.get("wangdianName"):"")},	//行1
			{xtype: 'button',handler:function(){citysWin(cityOptions);}, name: 'province_city_district',id:"province_city_district",fieldLabel: '选择城市',text:'选择',width: 120,height:22},
			{ // 行2
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'province',id:'province',fieldLabel: '所在城市',width: 150,allowBlank:false,blankText: '省不能为空',value:(row?row.get("province"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 60,
						items: [{xtype: 'textfield',name:'city',id:'city',fieldLabel: '市',width: 70,value:(row?row.get("city"):"")}]
					},
					{
						hidden:true,
						//columnWidth: .33,
						layout: "form",
						labelWidth: 12,
						items: [{xtype: 'textfield',name:'district',id:'district',fieldLabel: '区',width: 70,value:(row?row.get("district"):"")}]
					}
				]
			},
			{ //行3
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5, // 该列有整行中所占百分比
						layout: "form", // 从上往下的布局
						labelWidth: 120,
						items: [{xtype: 'textfield',name:'wangdianAddress',fieldLabel: '网点地址',width: 150,allowBlank:false,blankText: '网点地址不能为空',value:(row?row.get("wangdianAddress"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						labelWidth: 120,
						items: [{xtype: 'button',handler:function(){showWin_Lnglat(wangdianAddressLnglat,Ext.getCmp("wangdianAddressLng").getValue(),Ext.getCmp("wangdianAddressLat").getValue());}, name: 'latlng_wangdianAddress',id:"latlng_wangdianAddress",fieldLabel: '网点地址位置',text:'地图标注',width: 120,height:22}]
					}
				]
			},
			{ // 行4
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianAddressLng',id:'wangdianAddressLng',fieldLabel: '网点地址经度',width: 150,allowBlank:false,blankText: '经度不能为空',value:(row?row.get("wangdianAddressLng"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'wangdianAddressLat',id:'wangdianAddressLat',fieldLabel: '网点地址纬度',width: 150,allowBlank:false,blankText: '纬度不能为空',value:(row?row.get("wangdianAddressLat"):"")}]
					}
				]
			},
			
			{ // 行5
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianOwen',fieldLabel: '网点所属客户',width: 150,allowBlank:false,blankText: '网点所属客户不能为空',value:(row?row.get("wangdianOwen"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						//items: [{xtype: 'textfield',name:'wangdianAreaOwen',fieldLabel: '网点所属片区',width: 150,allowBlank:false,blankText: '网点所属片区不能为空',value:(row?row.get("wangdianAreaOwen"):"")}]
						items: [comboxWithTreeWangDian]
					}
				]
			},
			{ // 行6
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianfuzeren',fieldLabel: '网点负责人',width: 150,allowBlank:false,blankText: '网点负责人不能为空',value:(row?row.get("wangdianfuzeren"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'wdfzrTel',fieldLabel: '网点负责人联系方式',width: 150,allowBlank:false,blankText: '网点负责人联系方式不能为空',value:(row?row.get("wdfzrTel"):"")}]
					}
				]
			},
			{ // 行7
				layout: "column", // 从左往右的布局
				items: [
					{
						columnWidth: .5,
						layout: "form", // 从上往下的布局
						items: [{xtype: 'textfield',name:'wangdianyewuren',fieldLabel: '网点业务人',width: 150,allowBlank:false,blankText: '网点业务人员不能为空',value:(row?row.get("wangdianyewuren"):"")}]
					},
					{
						columnWidth: .5,
						layout: "form",
						items: [{xtype: 'textfield',name:'wdywrTel',fieldLabel: '网点业务人联系方式',width: 150,allowBlank:false,blankText: '网点业务人联系方式不能为空',value:(row?row.get("wdywrTel"):"")}]
					}
				]
			},
			{xtype: 'hidden',name:'saleId',value:(row?row.get("saleId"):"")},
			//{xtype: 'textfield',name:'wangdianPhoto',id:'wangdianPhoto',fieldLabel: '网点照片路径',width: 250,allowBlank:false,blankText: '',value:(row?row.get("wangdianPhoto"):"")},
			
			{
				xtype : 'textfield',
				fieldLabel : '图片地址1', 
				name : 'wangdianPhoto', 
				id:'wangdianPhoto',
				inputType : 'file',
				width : 260,
				//allowBlank : true,
				//blankText : '文件不能为空', 
				height : 25,
				anchor : '90%'
			},
			
			/*{
				text: '网点照片路径',
				icon: "img/chart_pie_add.png",
				cls: "x-btn-text-icon",
				handler: function(){
					Ext.QuickTips.init();//开启表单提示
					//hall_form_obj = getHallForm();
					wangDian_win_img = new Ext.Window(
						{
							title:'图片上传',
							id:'win',
							width:400,
							height:252,
							modal : true,
							maximizable:true,
							items:wandDianImgFileUpload()
						}
					);
					wangDian_win_img.show();
				}
			},*/
			{xtype: 'textarea',fieldLabel: '备注信息',id: 'beizhu',anchor: '70%',name:'beizhu',height: 90,value:(row?row.get("beizhu"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(wangdian_win.getComponent('wangdian_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (wangdian_win.getComponent('wangdian_form').form.isValid()) {
					wangdian_win.getComponent('wangdian_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_wangdianInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							//alert(Result.success);
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加网点信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改网点信息成功!');
								}
								wangdian_win.getComponent('wangdian_form').form.reset();
								wangdian_search.load({params: {start: 0,limit:20}});
								wangdian_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加网点信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改网点信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							wangdian_search.load({params: {start: 0}});
							wangdian_win.getComponent('wangdian_form').form.reset();
							//wangdian_win.getComponent('wangdian_form').findById("hall_ezmarker").reset();
						}
						
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				wangdian_win.close();
			}
		}]
	});
}

function wandDianImgFileUpload(){
	var img = new Ext.FormPanel({
		region : 'center', 
		labelWidth : 70, 
		frame : true,
		bodyStyle : 'padding:5px 5px 0', 
		autoScroll : true, 
		border : false, 
		fileUpload : true, 
		items : [
			{
				xtype : 'textfield',
				fieldLabel : '图片地址', 
				name : 'userfile1', 
				id:'file1', 
				inputType : 'file',
				width : 260,
				//allowBlank : true,
				//blankText : '文件不能为空', 
				height : 25,
				anchor : '90%'
			}
		],
		buttons : [
			{
				text : '确定',
				type : 'submit',
				handler : function(){
					if(document.getElementById("file1").value == '') return; 
					//if(document.getElementById("file").value == '') return; 
					//if (!img.form.isValid()) {return;}
					img.form.submit(
						{
							waitTitle: '请稍候',
							waitMsg : '正在上传 ......', 
							url : imgUrl, 
							success : function(form, action) { 
								wangDian_win_img.close();
								if(action.result.message == 0){Ext.MessageBox.alert('提示', '上传成功');}
								//Ext.MessageBox.alert('提示', action.result.message);
								//ds_icon_img.load({params:{start:0,limit:20}});
							},
							failure : function(form, action) { 
								wangDian_win_img.close();
								if(action.result.message == 1){Ext.MessageBox.alert('提示', '上传失败');}
								//Ext.MessageBox.alert('提示', action.result.message);
								//ds_icon_img.load({params:{start:0,limit:20}});
							}
						}
					);
				}
			},
			{
				text : '关闭',
				type : 'submit',
				handler : function() {
					wangDian_win_img.close();
				}
			}
		]
	});
	return img;
}

function wangdianAddressLnglat(point,zoom)
{
	LTEvent.removeListener(ezmarkerEvent);
	Ext.getDom("wangdianAddressLng").value = point.getLongitude();
	Ext.getDom("wangdianAddressLat").value = point.getLatitude();
	document.getElementById("ezmarkerDiv").style.display = "none";
	document.getElementById("ezmarkerDivClose").style.display = "none";
}
//excel
function excelFileUploadwd(){
	var excel = new Ext.FormPanel({
		region : 'center', 
		labelWidth : 35, 
		frame : true,
		bodyStyle : 'padding:5px 5px 0', 
		autoScroll : true, 
		border : false, 
		fileUpload : true, 
		items : [
			{
				xtype : 'textfield',
				fieldLabel : '文件', 
				name : 'file', 
				id:'file', 
				inputType : 'file',
				width : 260,
				allowBlank : true,
				blankText : '文件不能为空', 
				height : 25,
				anchor : '90%'
			},
			{
				bodyStyle:"padding-left:60px",
				html:"<br/><span><font color='#666666'></font></span>" 
			}
		],
		buttons : [
			{
				text : '确定',
				type : 'submit',
				handler : function() {
					if(document.getElementById("file").value == '') return; 
					if (!excel.form.isValid()) {return;}
					excel.form.submit(
						{
							waitTitle: '请稍候',
							waitMsg : '正在上传 ......', 
							url : 'Save_wdInfo.asp', 
							success : function(form, action) { 
								wangdian_win.close();
								//alert("开始");
								//alert(obj2str(action.result));
								Ext.MessageBox.alert('提示', action.result.message);
								
								wangdian_search.load({params:{start:0,limit:20}});
								//alert("上传成功");
							},
							failure : function(form, action) { 
								wangdian_win.close();
								Ext.MessageBox.alert('提示', action.result.message);
								//alert("上传失败");
							}
						}
					);
				}
			},
			{
				text : '关闭',
				type : 'submit',
				handler : function() {
					wangdian_win.close();
				}
			}
		]
	});
	return excel;
}

//--------------------------------网点信息管理结束-------------------------------------------------	


//--------------------------------标注图标管理开始-------------------------------------------------	

var iconInfo_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var iconInfo_cm = new Ext.grid.ColumnModel([iconInfo_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'标注图标名称',align:'center',dataIndex:'iconInfoName',width: 150},
	{header:'标注图标路径',align:'center',dataIndex:'iconInfoRoute',width: 200},
	{header:'图标预览',align:'center',dataIndex:'imgPreview',renderer:imgPreview}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_iconInfo = new Ext.data.HttpProxy({url:'json_iconInfoSearch.asp'});
var reader_iconInfo = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'iconInfoName'},
		{name:'iconInfoRoute'},
		{name:'imgPreview'}
	]
);
//构建Store
iconInfo_search = new Ext.data.Store({
	proxy:proxy_iconInfo,
	reader:reader_iconInfo
});

var grid_iconInfo = new Ext.grid.GridPanel({
	store: iconInfo_search,
	cm: iconInfo_cm,
	loadMask: true,
	//closable: true,
	title: '标注图标列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:iconInfo_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'iconInfoNameKeyWord',name:'iconInfoNameKeyWord',allowBlank: true,emptyText: "搜索图标名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				iconInfo_search.removeAll();
				iconInfo_search.load({
					params:{
						start: 0,
						limit:20,
						iconInfoNameKeyWord:grid_iconInfo.getTopToolbar().findById("iconInfoNameKeyWord").getValue()
					},callback:function(r,options,success){if(iconInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',
			icon: "img/chart_pie_add.png",
			cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				iconInfo_form_obj = imgFileUpload();
				iconInfo_win = new Ext.Window({title: "添加图标信息",width: 400,height: 180,modal: true,maximizable:false,resizable:false,items: iconInfo_form_obj});
				iconInfo_win.show();
			}
		},
			
//		{
//			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
//			handler: function(){
//				Ext.QuickTips.init();//开启表单提示
//				iconInfo_form_obj = imgFileUpload();
//				iconInfo_win = new Ext.Window({title: "添加图标信息",width: 500,height: 200,modal: true,maximizable:false,resizable:false,items: iconInfo_form_obj});
//				iconInfo_win.show();
//			}
//		},
//		{xtype: "tbseparator"},
//		{
//			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
//			handler: function(){
//				Ext.QuickTips.init();//开启表单提示
//				var row = grid_iconInfo.getSelectionModel().getSelections();
//				if (!row){return;}
//				for (var i = 0; i < row.length; i++)
//				{
//					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
//					iconInfo_form_obj = geticonInfoForm(row[i]);
//					iconInfo_win = new Ext.Window({title: "修改图标信息",width: 500,height: 200,modal: true,maximizable:false,resizable:false,items: iconInfo_form_obj});
//					iconInfo_win.show();
//					//field = hall_form_obj.getForm().findField('icon');
//					//field.setValue(row[i].get("icon"));//new
//					//alert(row[i].get("icon"))
//				}
//			}
//		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_iconInfo.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_iconInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							iconInfo_search.removeAll();
							iconInfo_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

function imgFileUpload(row){
	var img = new Ext.FormPanel({
		region : 'center', 
		labelWidth : 70, 
		frame : true,
		bodyStyle : 'padding:5px 5px 0', 
		autoScroll : true, 
		border : false, 
		fileUpload : true, 
		items : [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'iconInfoName',fieldLabel: '图标名称',width:200,allowBlank:false,blankText: '图标名称不能为空',value:(row?row.get("iconInfoName"):"")},
			{
				xtype : 'textfield',
				fieldLabel : '图片地址', 
				name : 'userfile1', 
				id:'file1', 
				inputType : 'file',
				width : 260,
				//allowBlank : true,
				//blankText : '文件不能为空', 
				height : 25,
				anchor : '90%'
			},
			{
				bodyStyle:"padding-left:60px",
				html:"<br/><span><font color='#666666'></font></span>" 
			}
		],
		buttons : [
			{
				text : '确定',
				type : 'submit',
				handler : function(){
					if(document.getElementById("file1").value == '' ) return; 
					//if (!img.form.isValid()) {return;}
					img.form.submit(
						{
							waitTitle: '请稍候',
							waitMsg : '正在上传 ......', 
							url : "json_iconInfoSave.asp?sType=add",
							method: 'POST',
							success: function(form,action){
								var Result = action.result;
								if (Result.success == true) {
									if(Result.msg==0){
										Ext.MessageBox.alert('提示','添加图标信息成功!');
									}else if(Result.msg==3){
										Ext.MessageBox.alert('提示','修改图标信息成功!');
									}
									iconInfo_win.close();
									iconInfo_search.load({params: {start: 0,limit:20}});
									//iconInfo_win.getComponent('img').form.reset();
									
								}
								else
								{
									if(Result.msg==1){
										Ext.MessageBox.alert('提示','添加图标信息失败!');
									}else if(Result.msg==4){
										Ext.MessageBox.alert('提示','修改图标信息失败!');
									}
								}
							},
							failure: function(form,action){
								//Ext.MessageBox.alert('提示', Result.message);
								//Ext.MessageBox.alert('提示', Result.msg);
								iconInfo_search.load({params: {start: 0}});
							//	iconInfo_win.getComponent('img').form.reset();
							}
						}
					);
				}
			},
			{
				text : '关闭',
				type : 'submit',
				handler : function() {
					iconInfo_win.close();
				}
			}
		]
	});
	return img;
}
//
////生成新加机构点的菜单
//function geticonInfoForm(row)
//{
//	return new Ext.FormPanel({
//		id: 'iconInfo_form',
//		name: 'iconInfo_form',
//		//title: "",
//		//bodyStyle: 'padding:5px 5px 0',
//		enctype:'multipart/form-data',
//		width: 500,
//		autoHeight: true,
//		frame: true,
//		renderTo: Ext.getBody(),
//		layout: "form", // 整个大的表单是form布局
//		labelWidth: 120,
//		labelAlign: "right",
//		items: [
//			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
//			{xtype: 'textfield',name:'iconInfoName',fieldLabel: '图标名称',width:200,allowBlank:false,blankText: '图标名称不能为空',value:(row?row.get("iconInfoName"):"")},
//			{
//				xtype : 'textfield',
//				fieldLabel : '图片地址', 
//				name : 'userfile1', 
//				id:'file1', 
//				inputType : 'file',
//				width : 260,
//				//allowBlank : true,
//				//blankText : '文件不能为空', 
//				height : 25,
//				anchor : '90%'
//			},
//			{
//				bodyStyle:"padding-left:60px",
//				html:"<br/><span><font color='#666666'></font></span>" 
//			}
//		],
//		buttons: [{
//			text: '确定',
//			type : 'submit',
//			handler: function(){//添加网站
//			//alert(iconInfo_win.getComponent('iconInfo_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
//				if(document.getElementById("file1").value == '') return; 
//				if (iconInfo_win.getComponent('iconInfo_form').form.isValid()) {
//					iconInfo_win.getComponent('iconInfo_form').form.submit({
//						waitTitle: '请稍候',
//						waitMsg: '正在提交数据,请稍候....',
//						url: 'json_iconInfoSave.asp?sType=add',
//						method: 'POST',
//						success: function(form,action){
//							var Result = action.result;
//							if (Result.success == true) {
//								if(Result.msg==0){
//									Ext.MessageBox.alert('提示','添加图标信息成功!');
//								}else if(Result.msg==3){
//									Ext.MessageBox.alert('提示','修改图标信息成功!');
//								}
//								iconInfo_win.getComponent('iconInfo_form').form.reset();
//								iconInfo_search.load({params: {start: 0,limit:20}});
//								iconInfo_win.close();
//							}
//							else
//							{
//								if(Result.msg==1){
//									Ext.MessageBox.alert('提示','添加图标信息失败!');
//								}else if(Result.msg==4){
//									Ext.MessageBox.alert('提示','修改图标信息失败!');
//								}
//							}
//						},
//						failure: function(form,action){
//							//Ext.MessageBox.alert('提示', Result.message);
//							//Ext.MessageBox.alert('提示', Result.msg);
//							iconInfo_search.load({params: {start: 0}});
//							iconInfo_win.getComponent('iconInfo_form').form.reset();
//							//iconInfo_win.getComponent('iconInfo_form').findById("hall_ezmarker").reset();
//						}
//						
//					})
//				}
//			}
//		}, {
//			text: '取消',
//			handler: function(){
//				iconInfo_win.close();
//			}
//		}]
//	});
//}


//--------------------------------标注图标管理结束-------------------------------------------------	


//--------------------------------行程管理开始--------------------------------------------------
var routeInfo_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var routeInfo_cm = new Ext.grid.ColumnModel([routeInfo_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'标题',dataIndex:'roadTitle'},
	{header:'起点经度',dataIndex:'lng'},
	{header:'起点纬度',dataIndex:'lat'},
	{header:'日期',dataIndex:'roadDate'},
	{header:'访问客户或网点',dataIndex:'roadTarget'},
	{header:'客户或网点所属城市',dataIndex:'cityName'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_routeInfo = new Ext.data.HttpProxy({url:'json_roadInfoSearch.asp'});
var reader_routeInfo = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'roadTitle'},
		{name:'lng'},
		{name:'lat'},
		{name:'roadDate'},
		{name:'roadTarget'},
		{name:'cityName'}
	]
);
//构建Store
routeInfo_search = new Ext.data.Store({
	proxy:proxy_routeInfo,
	reader:reader_routeInfo
/*		,
	baseParams:{limit:5}*/
});

var grid_routeInfo = new Ext.grid.GridPanel({
	store: routeInfo_search,
	cm: routeInfo_cm,
	loadMask: true,
	//closable: true,
	title: '行程信息列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:routeInfo_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'roadTileWord',name:'roadTileWord',allowBlank: true,emptyText: "搜索行程标题"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				routeInfo_search.removeAll();
				routeInfo_search.load({
					params:{
						start: 0,
						limit:20,
						roadTileWord:grid_routeInfo.getTopToolbar().findById("roadTileWord").getValue()
					},callback:function(r,options,success){if(routeInfo_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{xtype: "tbseparator"},
		{
			text: '行程导入',
			icon: "img/chart_pie_add.png",
			cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				//hall_form_obj = getHallForm();
				routeInfo_win = new Ext.Window(
					{
						title:'行程导入',
						id:'win',
						width:400,
						height:130,
						modal : true,
						maximizable:true,
						items:excelFileUpload()
					}
				);
				routeInfo_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_routeInfo.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_roadInfoDelete.asp',
									params: 'id=' + row[i].get("id")
								});
							}
							routeInfo_search.removeAll();
							routeInfo_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		},
		{xtype: "tbseparator"}, 
		{
			text: 'Excel模版下载',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				//window.open
				window.location.href = "download/行程数据.xls";
			}
		}
	]
});

function excelFileUpload(){
	var excel = new Ext.FormPanel({
		region : 'center', 
		labelWidth : 35, 
		frame : true,
		bodyStyle : 'padding:5px 5px 0', 
		autoScroll : true, 
		border : false, 
		fileUpload : true, 
		items : [
			{
				xtype : 'textfield',
				fieldLabel : '文件', 
				name : 'file', 
				id:'file', 
				inputType : 'file',
				width : 260,
				allowBlank : true,
				blankText : '文件不能为空', 
				height : 25,
				anchor : '90%'
			},
			{
				bodyStyle:"padding-left:60px",
				html:"<br/><span><font color='#666666'></font></span>" 
			}
		],
		buttons : [
			{
				text : '确定',
				type : 'submit',
				handler : function() {
					if(document.getElementById("file").value == '') return; 
					if (!excel.form.isValid()) {return;}
					excel.form.submit(
						{
							waitTitle: '请稍候',
							waitMsg : '正在上传 ......', 
							url : "Save.asp", 
							success : function(form, action) { 
								routeInfo_win.close();
								//alert("开始");
								//alert(obj2str(action.result));
								Ext.MessageBox.alert('提示', action.result.message);
								
								routeInfo_search.load({params:{start:0,limit:20}});
								//alert("上传成功");
							},
							failure : function(form, action) { 
								routeInfo_win.close();
								Ext.MessageBox.alert('提示', action.result.message);
								//alert("上传失败");
							}
						}
					);
				}
			},
			{
				text : '关闭',
				type : 'submit',
				handler : function() {
					routeInfo_win.close();
				}
			}
		]
	});
	return excel;
}
//--------------------------------行程管理结束-------------------------------------------------	


//--------------------------------部门管理开始-------------------------------------------------	
var department_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var department_cm = new Ext.grid.ColumnModel([department_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'部门名称',dataIndex:'departmentName'}
	
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_department = new Ext.data.HttpProxy({url:'json_departmentInfoSearch.asp'});
var reader_department = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'departmentName'}
		
	]
);
//构建Store
department_search = new Ext.data.Store({
	proxy:proxy_department,
	reader:reader_department
});

var grid_department = new Ext.grid.GridPanel({
	store: department_search,
	cm: department_cm,
	loadMask: true,
	//closable: true,
	title: '部门管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:department_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'departmentKeyWord',name:'departmentKeyWord',allowBlank: true,emptyText: "搜部门名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				department_search.removeAll();
				department_search.load({
					params:{
						start: 0,
						limit:20,
						departmentKeyWord:grid_department.getTopToolbar().findById("departmentKeyWord").getValue()
					},callback:function(r,options,success){if(department_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				department_form_obj = getDepartmentForm();
				department_win = new Ext.Window({title: "添加部门信息",width: 360,height: 105,modal: true,maximizable:false,resizable:false,items: department_form_obj});
				department_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_department.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					department_form_obj = getDepartmentForm(row[i]);
					department_win = new Ext.Window({title: "修改部门信息",width: 360,height: 105,modal: true,maximizable:false,resizable:false,items: department_form_obj});
					department_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_department.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_departmentInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							department_search.removeAll();
							department_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getDepartmentForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'department_form',
		name: 'department_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'departmentName',fieldLabel: '部门名称',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("departmentName"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (department_win.getComponent('department_form').form.isValid()) {
					department_win.getComponent('department_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_departmentInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加部门信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改部门信息成功!');
								}
								department_win.getComponent('department_form').form.reset();
								department_search.load({params: {start: 0,limit:20}});
								department_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加部门信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改部门信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							department_search.load({params: {start: 0}});
							department_win.getComponent('department_form').form.reset();
							//customerInfo_win.getComponent('department_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				department_win.close();
			}
		}]
	});
}

//--------------------------------部门管理结束-------------------------------------------------	


//--------------------------------采集管理开始-------------------------------------------------
var getPositionMsg_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var getPositionMsg_cm = new Ext.grid.ColumnModel([getPositionMsg_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'网点名称',dataIndex:'wangdianName'},
	{header:'网点编号',dataIndex:'wangdianNumber'},
	{header:'重要地标名称',dataIndex:'landmarksName'},
	{header:'地址',dataIndex:'positionAddress'},
	{header:'经度',dataIndex:'lng'},
	{header:'纬度',dataIndex:'lat'},
	//{header:'网点照片',dataIndex:'wangdianPhone'}
	{header:'照片预览',align:'center',dataIndex:'wangdianPhoneImgPreview1',renderer:phoneImgPreview1},
]);

function phoneImgPreview1(value,cellmeta,record,store){
	var str="<img src='"+ record.data["wangdianPhone"] +"' width='100' height='100'>";
	return str;
}

//start 读取远程POI JSON数据显示在表格里
var proxy_getPositionMsg = new Ext.data.HttpProxy({url:'json_getPositionMsgInfoSearch.asp'});
var reader_getPositionMsg = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'wangdianName'},
		{name:'wangdianNumber'},
		{name:'landmarksName'},
		{name:'positionAddress'},
		{name:'lng'},
		{name:'lat'},
		{name:'wangdianPhone'},
		{name:'wangdianPhoneImgPreview1'}
	]
);
//构建Store
getPositionMsg_search = new Ext.data.Store({
	proxy:proxy_getPositionMsg,
	reader:reader_getPositionMsg
});

var grid_getPositionMsg = new Ext.grid.GridPanel({
	store: getPositionMsg_search,
	cm: getPositionMsg_cm,
	loadMask: true,
	//closable: true,
	title: '采集管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:getPositionMsg_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'getPositionMsgKeyWord',name:'getPositionMsgKeyWord',allowBlank: true,emptyText: "搜采集的网点名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				getPositionMsg_search.removeAll();
				getPositionMsg_search.load({
					params:{
						start: 0,
						limit:20,
						getPositionMsgKeyWord:grid_getPositionMsg.getTopToolbar().findById("getPositionMsgKeyWord").getValue()
					},callback:function(r,options,success){if(getPositionMsg_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				getPositionMsg_form_obj = getDepartmentForm_getPositionMsg();
				getPositionMsg_win = new Ext.Window({title: "添加采集网点信息",width: 360,height: 240,modal: true,maximizable:false,resizable:false,items: getPositionMsg_form_obj});
				getPositionMsg_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_getPositionMsg.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					getPositionMsg_form_obj = getDepartmentForm_getPositionMsg(row[i]);
					getPositionMsg_win = new Ext.Window({title: "修改采集网点信息",width: 360,height: 240,modal: true,maximizable:false,resizable:false,items: getPositionMsg_form_obj});
					getPositionMsg_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_getPositionMsg.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_getPositionMsgInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							getPositionMsg_search.removeAll();
							getPositionMsg_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getDepartmentForm_getPositionMsg(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'getPositionMsg_form',
		name: 'getPositionMsg_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'wangdianName',fieldLabel: '网点名称',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("wangdianName"):"")},
			{xtype: 'textfield',name:'wangdianNumber',fieldLabel: '网点编号',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("wangdianNumber"):"")},
			{xtype: 'textfield',name:'landmarksName',fieldLabel: '重要地标名称',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("landmarksName"):"")},
			{xtype: 'textfield',name:'positionAddress',fieldLabel: '地址',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("positionAddress"):"")},
			{xtype: 'textfield',name:'lng',fieldLabel: '经度',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("lng"):"")},
			{xtype: 'textfield',name:'lat',fieldLabel: '纬度',width:150,allowBlank:false,blankText: '部门名称不能为空',value:(row?row.get("lat"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (getPositionMsg_win.getComponent('getPositionMsg_form').form.isValid()) {
					getPositionMsg_win.getComponent('getPositionMsg_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_getPositionMsgInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加部门信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改部门信息成功!');
								}
								getPositionMsg_win.getComponent('getPositionMsg_form').form.reset();
								getPositionMsg_search.load({params: {start: 0,limit:20}});
								getPositionMsg_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加部门信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改部门信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							getPositionMsg_search.load({params: {start: 0}});
							getPositionMsg_win.getComponent('getPositionMsg_form').form.reset();
							//customerInfo_win.getComponent('getPositionMsg_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				getPositionMsg_win.close();
			}
		}]
	});
}

//--------------------------------采集管理结束-------------------------------------------------	


//--------------------------------人员定位管理开始-------------------------------------------------
var getPositionUser_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var getPositionUser_cm = new Ext.grid.ColumnModel([getPositionUser_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'人员名称',dataIndex:'userName'},
	{header:'描述信息',dataIndex:'info'},
	{header:'经度',dataIndex:'lng'},
	{header:'纬度',dataIndex:'lat'},
	{header:'上传时间',dataIndex:'dateTime'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_getPositionUser = new Ext.data.HttpProxy({url:'json_getPositionUserInfoSearch.asp'});
var reader_getPositionUser = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'userId'},
		{name:'userName'},
		{name:'state'},
		{name:'info'},
		{name:'lng'},
		{name:'lat'},
		{name:'dateTime'}
	]
);
//构建Store
getPositionUser_search = new Ext.data.Store({
	proxy:proxy_getPositionUser,
	reader:reader_getPositionUser
});

var grid_getPositionUser = new Ext.grid.GridPanel({
	store: getPositionUser_search,
	cm: getPositionUser_cm,
	loadMask: true,
	//closable: true,
	title: '人员定位管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:getPositionUser_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'getPositionUserKeyWord',name:'getPositionUserKeyWord',allowBlank: true,emptyText: "搜索人员名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				getPositionUser_search.removeAll();
				getPositionUser_search.load({
					params:{
						start: 0,
						limit:20,
						getPositionUserKeyWord:grid_getPositionUser.getTopToolbar().findById("getPositionUserKeyWord").getValue()
					},callback:function(r,options,success){if(getPositionUser_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		/*{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				getPositionUser_form_obj = getDepartmentForm();
				getPositionUser_win = new Ext.Window({title: "添加采集网点信息",width: 360,height: 230,modal: true,maximizable:false,resizable:false,items: getPositionUser_form_obj});
				getPositionUser_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_getPositionUser.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					getPositionUser_form_obj = getDepartmentForm(row[i]);
					getPositionUser_win = new Ext.Window({title: "修改采集网点信息",width: 360,height: 230,modal: true,maximizable:false,resizable:false,items: getPositionUser_form_obj});
					getPositionUser_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},*/
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_getPositionUser.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_uploadPositionInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							getPositionUser_search.removeAll();
							getPositionUser_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//--------------------------------人员定位管理结束-------------------------------------------------	


//--------------------------------职位管理开始-------------------------------------------------	
var position_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var position_cm = new Ext.grid.ColumnModel([position_sm,
	{header:'编号',dataIndex:'id',hidden:true},
	{header:'职位名称',dataIndex:'positionName'}
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_position = new Ext.data.HttpProxy({url:'json_positionInfoSearch.asp'});
var reader_position = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'positionName'}
	]
);
//构建Store
position_search = new Ext.data.Store({
	proxy:proxy_position,
	reader:reader_position
});

var grid_position = new Ext.grid.GridPanel({
	store: position_search,
	cm: position_cm,
	loadMask: true,
	//closable: true,
	title: '职位管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:position_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'positionKeyWord',name:'positionKeyWord',allowBlank: true,emptyText: "搜职位名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				position_search.removeAll();
				position_search.load({
					params:{
						start: 0,
						limit:20,
						positionKeyWord:grid_position.getTopToolbar().findById("positionKeyWord").getValue()
					},callback:function(r,options,success){if(position_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				position_form_obj = getPositionForm();
				position_win = new Ext.Window({title: "添加职位信息",width: 360,height: 105,modal: true,maximizable:false,resizable:false,items: position_form_obj});
				position_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_position.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					position_form_obj = getPositionForm(row[i]);
					position_win = new Ext.Window({title: "修改职位信息",width: 360,height: 105,modal: true,maximizable:false,resizable:false,items: position_form_obj});
					position_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_position.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_positionInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							position_search.removeAll();
							position_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getPositionForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'position_form',
		name: 'position_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 350,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'positionName',fieldLabel: '职位名称',width:150,allowBlank:false,blankText: '职位名称不能为空',value:(row?row.get("positionName"):"")}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (position_win.getComponent('position_form').form.isValid()) {
					position_win.getComponent('position_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_positionInfoSave.asp?sType=add',
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加职位信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改职位信息成功!');
								}
								position_win.getComponent('position_form').form.reset();
								position_search.load({params: {start: 0,limit:20}});
								position_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加职位信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改职位信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							position_search.load({params: {start: 0}});
							position_win.getComponent('position_form').form.reset();
							//customerInfo_win.getComponent('position_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				position_win.close();
			}
		}]
	});
}

//--------------------------------职位管理结束-------------------------------------------------	



//--------------------------------用户权理开始-------------------------------------------------	
var user_sm = new Ext.grid.CheckboxSelectionModel({header: " ",sortable: true,width: 20});
var user_cm = new Ext.grid.ColumnModel([user_sm,
	{header:'编号',dataIndex:'id'},
	{header:'用户名称',dataIndex:'username'},
	{header:'用户密码',dataIndex:'password'},
	{header:'用户权限',dataIndex:'p',hidden:true},
	{header:'网点查询行政区划权限',dataIndex:'v1',hidden:true}
	
]);
//start 读取远程POI JSON数据显示在表格里
var proxy_user = new Ext.data.HttpProxy({url:'json_userInfoSearch.asp'});
var reader_user = new Ext.data.JsonReader(
	{
		totalProperty:'mytotal',//记录总数
		root:'root',
		id:'id'
	},[
		{name:'id'},
		{name:'username'},
		{name:'password'},
		{name:'p'},
		{name:'v1'}
	]
);
//构建Store
user_search = new Ext.data.Store({
	proxy:proxy_user,
	reader:reader_user
});

var grid_user = new Ext.grid.GridPanel({
	store: user_search,
	cm: user_cm,
	loadMask: true,
	//closable: true,
	title: '用户管理列表',
	bbar: new Ext.PagingToolbar({
		pageSize:20,
		store:user_search,
		displayInfo:true,
		//displayMsg:'显示第{0}条到第和第{1}条记录,一共{2}条',
		displayMsg:'显示第 {0} 条到 {1} 条记录，总共 {2} 条',
		emptyMsg:'没有记录',
		beforePageText: "第",
		afterPageText:"页 共{0}页"
	}),
	tbar: [
		{xtype: "textfield",width: 160,height: 20,baseCls: 'x-plain',id:'userKeyWord',name:'userKeyWord',allowBlank: true,emptyText: "搜用户名称"},
		{xtype: "tbseparator"},
		{
			text: '&nbsp;搜索',icon: "img/page_find.png",cls: "x-btn-text-icon",
			handler: function(){
				//Ext.Msg.alert('提示','目前无数据');
				user_search.removeAll();
				user_search.load({
					params:{
						start: 0,
						limit:20,
						userKeyWord:grid_user.getTopToolbar().findById("userKeyWord").getValue()
					},callback:function(r,options,success){if(user_search.getCount() == 0){Ext.MessageBox.alert('提示', "搜索无结果");}}
				})
			}
		},
		{
			text: '添加',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				user_form_obj = getuserForm();
				user_win = new Ext.Window({title: "添加用户信息",width: 500,height: 385,modal: true,maximizable:false,resizable:false,items: user_form_obj});
				user_win.show();
			}
		},
		{xtype: "tbseparator"},
		{
			text: '修改',icon: "img/chart_pie_add.png",cls: "x-btn-text-icon",
			handler: function(){
				Ext.QuickTips.init();//开启表单提示
				var row = grid_user.getSelectionModel().getSelections();
				if (!row){return;}
				for (var i = 0; i < row.length; i++)
				{
					Ext.form.Field.prototype.msgTarget = 'side';//设置提示信息位置为边上
					user_form_obj = getuserForm(row[i]);
					user_win = new Ext.Window({title: "修改职位信息",width: 500,height: 385,modal: true,maximizable:false,resizable:false,items: user_form_obj});
					user_win.show();
					//field = hall_form_obj.getForm().findField('icon');
					//field.setValue(row[i].get("icon"));//new
					//alert(row[i].get("icon"))
				}
			}
		},
		{xtype: "tbseparator"},
		{
			text: '删除',icon: "img/chart_pie_delete.png",cls: "x-btn-text-icon",
			handler: function(){
				var row = grid_user.getSelectionModel().getSelections();
				if (row) {
					Ext.Msg.confirm("请确认", "是否真的删除此条记录?", function(butten, text){
						if (butten == "yes") {
							for (var i = 0; i < row.length; i++) {
								//alert(row[i].get("id"));
								Ext.Ajax.request({
									url: 'json_userInfoSave.asp?sType=del',
									params: 'id=' + row[i].get("id")
								});
							}
							user_search.removeAll();
							user_search.load({params: {start:0,limit:20}});
						}
					})
				}
			}
		}
	]
});

//生成新加机构点的菜单
function getuserForm(row)
{
	//网点数据结束
	return new Ext.FormPanel({
		id: 'user_form',
		name: 'user_form',
		//title: "",
		//bodyStyle: 'padding:5px 5px 0',
		width: 490,
		autoHeight: true,
		frame: true,
		renderTo: Ext.getBody(),
		layout: "form", // 整个大的表单是form布局
		labelWidth: 120,
		labelAlign: "right",
		items: [
			{xtype: 'hidden',name:'id',value:(row?row.get("id"):"")},
			{xtype: 'textfield',name:'username',fieldLabel: '用户名称',width:150,allowBlank:false,blankText: '用户名称不能为空',value:(row?row.get("username"):"")},
			{xtype: 'textfield',name:'password',fieldLabel: '密码',width:150,allowBlank:false,blankText: '密码不能为空',value:(row?row.get("password"):"")},
			{
				columnWidth : .100,
				fieldLabel: '用户查看权限',
				xtype : "panel",
				//bodyStyle : "background-color:block",
				frame:true,
				layout : "column",// 也可以是table,实现多列布局
				//fieldLabel : '爱好',
				isFormField : true,// 非常重要,否则panel默认不显示fieldLabel
				items : [
					{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "网点信息查询",
						name : "wdSearch",
						id : "wdSearch",
						inputValue : 1,
						checked:userTypeTF((row?row.get("p"):""),1)
					},
					{
						xtype: 'button',
						columnWidth: .40,
						handler:function(){citysWin(wdSecondCityOptions,3,row);}, 
						name: 'wdSecond_ID',
						id:"wdSecond_ID",
						fieldLabel: '网点区域',
						text:'请选择网点区域'
					},{
						hidden:true,
						xtype: 'hidden',
						name:'wdIdSecond',
						id:'wdIdSecond',
						fieldLabel: 'wd',
						width: 150
					},{
						xtype : "checkbox",
						columnWidth : .50,
						// anchor : '97%',
						boxLabel : "客户信息查询",
						name : "khSearch",
						id : "khSearch",
						inputValue : 2,
						checked:userTypeTF((row?row.get("p"):""),2)
					},{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "行程信息查询",
						name : "xzqhSearch",
						id : "xzqhSearch",
						inputValue : 3,
						checked:userTypeTF((row?row.get("p"):""),3)
					},{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "销售片区查询",
						name : "xspqSearch",
						id : "xspqSearch",
						inputValue : 4,
						checked:userTypeTF((row?row.get("p"):""),4)
					},{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "销售人员查询",
						name : "xsrySearch",
						id : "xsrySearch",
						inputValue : 5,
						checked:userTypeTF((row?row.get("p"):""),5)
					},{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "部门信息查询",
						name : "bmSearch",
						id : "bmSearch",
						inputValue : 6,
						checked:userTypeTF((row?row.get("p"):""),6)
					},{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "职位信息查询",
						name : "zwSearch",
						id : "zwSearch",
						inputValue : 7,
						checked:userTypeTF((row?row.get("p"):""),7)
					},{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "用户信息查询",
						name : "yhSearch",
						id : "yhSearch",
						inputValue : 8,
						checked:userTypeTF((row?row.get("p"):""),8)
					},{
						xtype : "checkbox",
						columnWidth : .50,
						boxLabel : "标注图标查询",
						name : "tbSearch",
						id : "tbSearch",
						inputValue : 9,
						checked:userTypeTF((row?row.get("p"):""),9)
					}
				]
			},
			{
				columnWidth : .100,
				fieldLabel: '数据管理权限',
				xtype : "panel",
				//bodyStyle : "background-color:block",
				frame:true,
				layout : "column",// 也可以是table,实现多列布局
				//fieldLabel : '爱好',
				isFormField : true,// 非常重要,否则panel默认不显示fieldLabel
				items : [
					{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "网点信息维护",
						name : "wdEdit",
						id : "wdEdit",
						inputValue : 10,
						checked:userTypeTF((row?row.get("p"):""),10)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						// anchor : '97%',
						boxLabel : "客户信息维护",
						name : "khEdit",
						id : "khEdit",
						inputValue : 11,
						checked:userTypeTF((row?row.get("p"):""),11)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "行程信息维护",
						name : "xzqhEdit",
						id : "xzqhEdit",
						inputValue : 12,
						checked:userTypeTF((row?row.get("p"):""),12)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "销售片区维护",
						name : "xspqEdit",
						id : "xspqEdit",
						inputValue : 13,
						checked:userTypeTF((row?row.get("p"):""),13)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "销售人员维护",
						name : "xsryEdit",
						id : "xsryEdit",
						inputValue : 14,
						checked:userTypeTF((row?row.get("p"):""),14)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "部门信息维护",
						name : "bmEdit",
						id : "bmEdit",
						inputValue : 15,
						checked:userTypeTF((row?row.get("p"):""),15)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "职位信息维护",
						name : "zwEdit",
						id : "zwEdit",
						inputValue : 16,
						checked:userTypeTF((row?row.get("p"):""),16)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "用户信息维护",
						name : "yhEdit",
						id : "yhEdit",
						inputValue : 17,
						checked:userTypeTF((row?row.get("p"):""),17)
					},{
						xtype : "checkbox",
						columnWidth : .40,
						boxLabel : "标注图标维护",
						name : "tbEdit",
						id : "tbEdit",
						inputValue : 18,
						checked:userTypeTF((row?row.get("p"):""),18)
					}
				]
			}
		],
		buttons: [{
			text: '确定',
			handler: function(){//添加网站
			//alert(customerInfo_win.getComponent('hall_form').form.findField("beginDateUpdate").getValue().replaceAll("-",","));
				if (user_win.getComponent('user_form').form.isValid()) {
					var useTypeUpdate = "";
					var wdSearch = user_win.getComponent('user_form').form.findField("wdSearch").getValue();
					var khSearch = user_win.getComponent('user_form').form.findField("khSearch").getValue();
					var xzqhSearch = user_win.getComponent('user_form').form.findField("xzqhSearch").getValue();
					var xspqSearch = user_win.getComponent('user_form').form.findField("xspqSearch").getValue();
					var xsrySearch = user_win.getComponent('user_form').form.findField("xsrySearch").getValue();
					var bmSearch = user_win.getComponent('user_form').form.findField("bmSearch").getValue();
					var zwSearch = user_win.getComponent('user_form').form.findField("zwSearch").getValue();
					var yhSearch = user_win.getComponent('user_form').form.findField("yhSearch").getValue();
					var tbSearch = user_win.getComponent('user_form').form.findField("tbSearch").getValue();

					var wdEdit = user_win.getComponent('user_form').form.findField("wdEdit").getValue();
					var khEdit = user_win.getComponent('user_form').form.findField("khEdit").getValue();
					var xzqhEdit = user_win.getComponent('user_form').form.findField("xzqhEdit").getValue();
					var xspqEdit = user_win.getComponent('user_form').form.findField("xspqEdit").getValue();
					var xsryEdit = user_win.getComponent('user_form').form.findField("xsryEdit").getValue();
					var bmEdit = user_win.getComponent('user_form').form.findField("bmEdit").getValue();
					var zwEdit = user_win.getComponent('user_form').form.findField("zwEdit").getValue();
					var yhEdit = user_win.getComponent('user_form').form.findField("yhEdit").getValue();
					var tbEdit = user_win.getComponent('user_form').form.findField("tbEdit").getValue();

					var arrTF = [wdSearch,khSearch,xzqhSearch,xspqSearch,xsrySearch,bmSearch,zwSearch,yhSearch,tbSearch,wdEdit,khEdit,xzqhEdit,xspqEdit,xsryEdit,bmEdit,zwEdit,yhEdit,tbEdit];
					for(var i=0;i<arrTF.length;i++)
					{
						if(arrTF[i])
						{
							useTypeUpdate += (i+1) + ",";
						}
						
						if(i==arrTF.length-1)
						{
							useTypeUpdate = useTypeUpdate.substring(0,useTypeUpdate.length-1);
						}
					}
					
					user_win.getComponent('user_form').form.submit({
						waitTitle: '请稍候',
						waitMsg: '正在提交数据,请稍候....',
						url: 'json_userInfoSave.asp?sType=add&useTypeUpdate='+useTypeUpdate,
						method: 'POST',
						success: function(form,action){
							var Result = action.result;
							if (Result.success == true) {
								if(Result.msg==0){
									Ext.MessageBox.alert('提示','添加用户信息成功!');
								}else if(Result.msg==3){
									Ext.MessageBox.alert('提示','修改用户信息成功!');
								}
								user_win.getComponent('user_form').form.reset();
								user_search.load({params: {start: 0,limit:20}});
								user_win.close();
							}
							else
							{
								if(Result.msg==1){
									Ext.MessageBox.alert('提示','添加用户信息失败!');
								}else if(Result.msg==4){
									Ext.MessageBox.alert('提示','修改用户信息失败!');
								}
							}
						},
						failure: function(form,action){
							//Ext.MessageBox.alert('提示', Result.message);
							//Ext.MessageBox.alert('提示', Result.msg);
							user_search.load({params: {start: 0}});
							user_win.getComponent('user_form').form.reset();
							//customerInfo_win.getComponent('user_form').findById("hall_ezmarker").reset();
						}
					})
				}
			}
		}, {
			text: '取消',
			handler: function(){
				user_win.close();
			}
		}]
	});
}
//给客户的所属城市赋值
function wdSecondCityOptions(cityArr)
{
	Ext.getDom("wdIdSecond").value = cityArr;
	//alert(Ext.getDom("wdIdSecond").value);
}
//--------------------------------用户管理结束-------------------------------------------------	



//--------------------------------公共方法开始-------------------------------------------------	

//-------------全国城市列表开始-----------------------------
//城市列表窗口，参数type为树是否有复选框，1表示没有，2表示有
function citysWin(fun,type,row)
{
	citys_form_obj = citysForm(fun,type,row);
	citys_win = new Ext.Window({title: "城市列表",width: 213,height:375,modal: true,maximizable: false,resizable:false,items: citys_form_obj});
	citys_win.show();
}
function citysForm(fun,type,row)
{
	if(typeof type == "undefined" || type ==1)
	{
		var treeJSON = citys_tree_obj;
	}
	else if(typeof type == "undefined" || type ==2)
	{
		var treeJSON = citys_tree_obj_checked;
	}
	else
	{
		if(row)
		{
			//----------------------------------
			//alert(row.get("v1"));
			var treeJSON = citys_tree_obj_checked;
			//初始选择被选中的节点
			for(var i=0;i<treeJSON.length;i++)	//全国
			{
				var childrens = treeJSON[i].children;
				//alert(treeJSON[i].children);
				for(var k=0;k<childrens.length;k++)	//省级
				{
					//alert(childrens[k].text);
					if(row.get("v1").indexOf(childrens[k].text) > -1)
					{
						childrens[k].checked = true;
					}
					else
					{
						childrens[k].checked = false;
					}
					if(childrens[k].children)
					{
						var childrens_seconde = childrens[k].children
						for(var m=0;m<childrens_seconde.length;m++)	//市级
						{
							if(row.get("v1").indexOf(childrens_seconde[m].text) > -1)
							{
								childrens_seconde[m].checked = true;
							}
							else
							{
								childrens_seconde[m].checked = false;
							}
							if(childrens_seconde[m].children)
							{
								var childrens_three = childrens_seconde[m].children
								for(var n=0;n<childrens_three.length;n++)	//区县级
								{
									if(row.get("v1").indexOf(childrens_three[n].text) > -1)
									{
										childrens_three[n].checked = true;
									}
									else
									{
										childrens_three[n].checked = false;
									}
								}
							}
						}
					}
				}
			}
			//----------------------------------------------
		}
		else
		{
			var treeJSON = citys_tree_obj_checked;
			//初始选择被选中的节点
			for(var i=0;i<treeJSON.length;i++)	//全国
			{
				var childrens = treeJSON[i].children;
				//alert(treeJSON[i].children);
				for(var k=0;k<childrens.length;k++)	//省级
				{
					childrens[k].checked = false;
					if(childrens[k].children)
					{
						var childrens_seconde = childrens[k].children
						for(var m=0;m<childrens_seconde.length;m++)	//市级
						{
							childrens_seconde[m].checked = false;
							if(childrens_seconde[m].children)
							{
								var childrens_three = childrens_seconde[m].children
								for(var n=0;n<childrens_three.length;n++)	//区县级
								{
									childrens_three[n].checked = false;
								}
							}
						}
					}
				}
			}
		}
	}
	//全国的城市列表
	var treeCitys = new Ext.tree.TreePanel({
		//el: 'tree',
		//loader: new Ext.tree.TreeLoader({dataUrl:"citys/tree.asp"}),
		loader: new Ext.tree.TreeLoader(),
		//title: '系统管理',
		split: true,
		//border: true,
		rootVisible:false,
		autoScroll: true,
		//autoScroll:false,
		//collapsible: true,
		enableAllCheck:true,	//给树增加复选框
		width: 200,
		height:300
		//,
		//minSize: 80
	});
	
	var root = new Ext.tree.AsyncTreeNode({
		text:'root'
		,
		children: treeJSON
	});
	
	// 设置树的点击事件
	function treeClick(node, e)
	{
		//alert(node.text);
		
		//获取所有子节点
		/*node.cascade( function( node ){
			node.attributes.checked = flag;
			node.ui.checkbox.checked = flag;
			return true;
		});*/
		nodeCity = [];
		nodeCity.push(node.text);
		try
		{
			//获取所有父节点
			var pNode = node.parentNode;
			for(;pNode.id !="root";pNode = pNode.parentNode ){
				//alert(pNode.text);
				if (treeCitys.getChecked(id, node.parentNode) == "")
				{
					//alert(pNode.text);
					if(pNode.text!="root"&&pNode.text!="全国")
					{
						nodeCity.push(pNode.text);
					}
					//pNode.ui.checkbox.checked = flag;
					//pNode.attributes.checked = flag;
				}
			}
		}catch(e){}
	}
	// 增加鼠标单击事件
	treeCitys.on('click', function(node,e){
		nodeCity = [];
		nodeCity.push(node.text);
		try
		{
			//获取所有父节点
			var pNode = node.parentNode;
			for(;pNode.id !="root";pNode = pNode.parentNode ){
				if (treeCitys.getChecked(id, node.parentNode) == "")
				{
					if(pNode.text!="root"&&pNode.text!="全国")
					{
						nodeCity.push(pNode.text);
					}
				}
			}
		}catch(e){}							   
	});
	// 增加复选框架单击事件
	treeCitys.on('checkchange', function(node, flag){
		
		//nodeCityChecked = [];
		if(type == 2)
		{
			if(flag == false)
			{
				removeStr(nodeCityChecked,node.text);	
				return;
			}
			
			nodeCityChecked.push(node.text);
		}
		
		if(type == 3)
		{
			var nodeCityQuanXianChecked = [];
			nodeCityQuanXianChecked.push(node.text);
			try
			{
				// 获取所有子节点
				node.cascade(function(node) {
					node.attributes.checked = flag;
					node.ui.checkbox.checked = flag;
//                  node.ui.toggleCheck(flag);
					return true;
				});
				
				//获取所有父节点
				var pNode = node.parentNode;
				for(;pNode.id !="root";pNode = pNode.parentNode ){
					//if (treeCitys.getChecked(id, node.parentNode) == "")
					//{
						if(flag || pNode.text!="root"&&pNode.text!="全国")
						{
							nodeCityQuanXianChecked.push(pNode.text);
							
							pNode.ui.checkbox.checked = true;
							pNode.attributes.checked = true;
							//pNode.ui.checkbox.checked = flag;
							//pNode.attributes.checked = flag;
							
							//alert(pNode.ui.checkbox.checked);
						}
					//}
				}
			}catch(e){}	
			var arrOnly = nodeCityQuanXianChecked.reverse().join("");
			nodeCityQuanXian.push(arrOnly);
			//alert(nodeCityQuanXian);
		}
		
		/*try	//预留防止客户更改业务
		{
			//获取所有父节点
			var pNode = node.parentNode;
			for(;pNode.id !="root";pNode = pNode.parentNode ){
				alert(pNode.text);
				if (checked || treeCitys.getChecked(id, node.parentNode) == "")
				{
					if(pNode.text!="root"&&pNode.text!="全国")
					{
						nodeCityChecked.push(pNode.text);
					}
					pNode.ui.checkbox.checked = checked;
					pNode.attributes.checked = checked;
				}
			}
		}catch(e){}*/
	});
	
	treeCitys.setRootNode(root);
	treeCitys.expand();
	//root.reload();
	//Ajax提交新增请求后，在callback中刷新treeCitys的根节点，然后定位到当前节点
	//var path = currentNode.getPath('id');
	//treeCitys.getRootNode().reload();	//刷新树
	//treeCitys.expandPath(path,'id');
	
	var nodeCity = [];	//不带复选框返回的值
	var nodeCityChecked = [];	//带复选框返回的值
	var nodeCityQuanXian = [];
	var form1 = new Ext.form.FormPanel({
		width:200,
		//height:200,
		//frame:true,//圆角和浅蓝色背景
		//renderTo:Ext.getBody(),//呈现
		//title:"FormPanel",
		//bodyStyle:"padding:5px 5px 0",
		//defaults:{xtype:"textfield",width:120},
		items:[
			treeCitys
		],
		buttons:[
			{text:"确定",handler:function(){
				if(typeof type == "undefined" || type ==1)
				{
					//不带复选框返回的值
					fun(nodeCity);
				}
				else if(typeof type == "undefined" || type ==2)
				{
					//带复选框返回的值
					fun(nodeCityChecked);
				}
				else
				{
					//-----------组织提交的数组开始------------------------
					
					//初始选择被选中的节点
					for(var i=0;i<treeJSON.length;i++)	//全国
					{
						var childrens = treeJSON[i].children;
						//alert(treeJSON[i].children);
						var quanxianArr = [];
						
						for(var k=0;k<childrens.length;k++)	//省级
						{
							//alert(childrens[k].text);
							var shengji = [];
							if(childrens[k].checked)
							{
								var shengjiFlag = nextFlag(childrens[k].children);
								//alert(shengjiFlag);
								if(shengjiFlag == false)
								{
									shengji.push(childrens[k].text);
									//quanxianArr.push(shengji.join(","));
									//break;
								}
								
								if(childrens[k].children)
								{
									var childrens_seconde = childrens[k].children
									//var shiji = [];
									
									var shengjiArr = [];
									for(var m=0;m<childrens_seconde.length;m++)	//市级
									{
										if(childrens_seconde[m].checked)
										{
											
											var shijiFlag = nextFlag(childrens_seconde[m].children);
											if(shijiFlag == false)
											{
												shengjiArr.push(childrens[k].text+childrens_seconde[m].text);
											}
											
											//shengjiArr.push(childrens[k].text+childrens_seconde[m].text);
											//shengji.push(childrens_seconde[m].text);
											
											if(childrens_seconde[m].children)
											{
												var childrens_three = childrens_seconde[m].children
												var shijiArr = [];
												for(var n=0;n<childrens_three.length;n++)	//区县级
												{
													if(childrens_three[n].checked)
													{
														shijiArr.push(childrens[k].text+childrens_seconde[m].text+childrens_three[n].text);
														//shengji.push(childrens_three[n].text);
													}
												}
												shengjiArr.push(shijiArr);
											}
										}

									}
									shengji.push(shengjiArr);
								}
								quanxianArr.push(shengji.join(","));
							}
						}
						
					}
					//alert(quanxianArr);
					//return;
					//-----------组织提交的数组结束------------------------
					//带复选框返回的值
					//fun(nodeCityQuanXian);
					fun(quanxianArr);
				}
				
				citys_win.close()}
			},
			{text:"取消",handler:function(){citys_win.close()}}]
	});
	return form1;
}


function nextFlag(childrens)
{
	//alert(childrens);
	var flag = false;
	if(childrens)
	{
		for(var n=0;n<childrens.length;n++)	//区县级
		{
			if(childrens[n].checked == true)
			{
				flag = true;
				break;
			}
		}
	}
	return flag;
}

/*
//-----------组织提交的数组开始------------------------
					
//初始选择被选中的节点
for(var i=0;i<treeJSON.length;i++)	//全国
{
	var childrens = treeJSON[i].children;
	//alert(treeJSON[i].children);
	var quanxianArr = [];
	
	for(var k=0;k<childrens.length;k++)	//省级
	{
		//alert(childrens[k].text);
		var shengji = [];
		if(childrens[k].checked)
		{
			shengji.push(childrens[k].text);
		}
		if(childrens[k].children)
		{
			var childrens_seconde = childrens[k].children
			//var shiji = [];
			for(var m=0;m<childrens_seconde.length;m++)	//市级
			{
				if(childrens_seconde[m].checked)
				{
					shengji.push(childrens_seconde[m].text);
				}
				if(childrens_seconde[m].children)
				{
					var childrens_three = childrens_seconde[m].children
					for(var n=0;n<childrens_three.length;n++)	//区县级
					{
						if(childrens_three[n].checked)
						{
							shengji.push(childrens_three[n].text);
						}
					}
				}
			}
		}
		if(shengji.length>0)
		{
			quanxianArr.push(shengji.join(""));
		}
	}
	
}
alert(quanxianArr);
return;
//-----------组织提交的数组结束------------------------
*/

//-------------全国城市列表结束-----------------------------

function indexOfStr(val,text){
	for(var i = 0; i < val.length; i++)
	{
		if(val[i] == text)return i;
	}
	return -1;
}
function removeStr(val,text){
	var index = indexOfStr(val,text);
	if (index > -1) {
		val.splice(index, 1);
	}
}
//图片预览
function imgPreview(value,cellmeta,record,store){
	var str="<img src='"+ record.data["iconInfoRoute"] +"' width='30' height='30'>";
	return str;
}
function imgPreview1(value,cellmeta,record,store){
	var str="<img src='"+ record.data["wangdianPhoto"] +"' width='100' height='100'>";
	return str;
}
function userTypeTF(value,key)
{
	if(value != ""){
		var un = value.indexOf(",");
		var flag = false;
		if(un >= 1)
		{
			var arr = value.split(",");
			for(var i=0;i<arr.length;i++)
			{
				if(arr[i] == key)
				{
					return true;
				}
			}
		}
		else if(value==key)
		{
			return true;
		}
	}
}





//将JSON对象转换成字符串
function obj2str(o){
	var r = [];
	if(typeof o =="string") return "\""+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
	if(typeof o =="undefined") return "";
	if(typeof o == "object"){
		if(o===null) return "null";
		else if(!o.sort){
			for(var i in o)
				r.push(i+":"+obj2str(o[i]))
			r="{"+r.join()+"}"
		}else{
			for(var i =0;i<o.length;i++)
				r.push(obj2str(o[i]))
			r="["+r.join()+"]"
		}
		return r;
	}
	return o.toString();
}
//--------------------------------公共方法结束-------------------------------------------------